mermaid/packages/parser
Sidharth Vinod 5cc20b5e44
Merge branch 'next' into feat/948_packetDiagram
* next: (316 commits)
  Lint
  Remove echo
  RefTest
  Echo event
  Update cypress
  Fix applitools
  Fix applitools
  docs: fix lint
  docs: move community to Discord
  Swap condition blocks to avoid using negation
  Reposition const declaration to ideal place
  Change repetitive values into consts
  docs: fix swimm link
  Fix Update Browserslist
  Use pnpm/action-setup@v2
  Fix lint
  Cleanup e2e.yml
  Ignore push events on merge queue
  Remove ::
  Remove ::
  ...
2024-01-24 00:58:55 +05:30
..
src refactor: Fix types 2023-11-15 09:25:49 +05:30
tests chore: increase `test-util.ts` converage by returning `undefined` 2023-08-26 14:37:36 +03:00
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 feat: Add packet diagram 2023-09-14 22:35:13 +05:30
package.json Move mermaid-parser to @mermaid-js/parser 2023-11-26 21:10:00 +05:30
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.