Files
mermaid/packages/parser
Sidharth Vinod 9a3498fba8 fix: Handle langium data loss warning
It's not an issue to actually lose the data, as we're just taking the last value anyways. But having the warnings clog up the console means we might miss actual warnings.
2025-04-15 09:48:50 +05:30
..
2025-04-15 09:48:50 +05:30
2025-03-25 11:37:21 +00:00
2025-03-16 18:00:50 +01:00
2025-03-25 11:37:21 +00:00

Mermaid Parser

Mermaid parser package

NPM

How the package works

The package exports a parse function that has two parameters:

declare function parse<T extends DiagramAST>(
  diagramType: keyof typeof initializers,
  text: string
): T;

How does a Langium-based parser work?

sequenceDiagram
actor Package
participant Module
participant TokenBuilder
participant Lexer
participant Parser
participant ValueConverter


Package ->> Module: Create services
Module ->> TokenBuilder: Override or/and<br>reorder rules
TokenBuilder ->> Lexer: Read the string and transform<br>it into a token stream
Lexer ->> Parser: Parse token<br>stream into AST
Parser ->> ValueConverter: Clean/modify tokenized<br>rules returned value
ValueConverter -->> Package: Return AST
  • When to override TokenBuilder?

    • To override keyword rules.
    • To override terminal rules that need a custom function.
    • To manually reorder the list of rules.
  • When to override Lexer?

    • To modify input before tokenizing.
    • To insert/modify tokens that cannot or have not been parsed.
  • When to override LangiumParser?

    • To insert or modify attributes that can't be parsed.
  • When to override ValueConverter?

    • To modify the returned value from the parser.