mermaid/packages/parser
Sidharth Vinod 1659ace65d
Fix spelling
2024-03-06 14:16:32 +05:30
..
src build(deps): update `langium` to `v3` and apply the required changes 2024-02-29 20:38:15 +03:00
tests Fix spelling 2024-03-06 14:16:32 +05:30
LICENSE feat: create `parser` package in `packages` directory 2023-08-20 15:31:40 +03:00
README.md Move mermaid-parser to @mermaid-js/parser 2023-11-26 21:17:08 +05:30
langium-config.json Merge branch next into add-pie-langium-parser 2024-01-25 14:56:34 +03:00
package.json build(deps): update `langium` to `v3` and apply the required changes 2024-02-29 20:38:15 +03:00
tsconfig.json feat: create `parser` package in `packages` directory 2023-08-20 15:31:40 +03:00

README.md

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.