mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
added parser
This commit is contained in:
@@ -1,6 +1,28 @@
|
||||
grammar GitGraph
|
||||
|
||||
import "../common/common";
|
||||
interface Common {
|
||||
accDescr?: string;
|
||||
accTitle?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
fragment TitleAndAccessibilities:
|
||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
||||
;
|
||||
|
||||
fragment EOL returns string:
|
||||
NEWLINE+ | EOF
|
||||
;
|
||||
|
||||
terminal NEWLINE: /\r?\n/;
|
||||
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
||||
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
||||
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
||||
|
||||
hidden terminal WHITESPACE: /[\t ]+/;
|
||||
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
||||
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
||||
hidden terminal SINGLE_LINE_COMMENT: /[\t ]*%%[^\n\r]*/;
|
||||
|
||||
entry GitGraph:
|
||||
NEWLINE*
|
||||
@@ -62,6 +84,8 @@ CherryPicking:
|
||||
|'parent:' id=STRING
|
||||
)* EOL;
|
||||
|
||||
|
||||
|
||||
terminal INT returns number: /[0-9]+(?=\s)/;
|
||||
terminal ID returns string: /\w([-\./\w]*[-\w])?/;
|
||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
||||
|
@@ -8,11 +8,23 @@ describe('gitGraph', () => {
|
||||
const result = parse(`gitGraph`);
|
||||
expect(result.value.$type).toBe(GitGraph);
|
||||
expect(result.value.statements).toHaveLength(0);
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should handle gitGraph with one statement', () => {
|
||||
const result = parse(`gitGraph\n A`);
|
||||
const result = parse(`gitGraph\n commit\n`);
|
||||
expect(result.value.$type).toBe(GitGraph);
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
expect(result.value.statements).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should handle gitGraph with multiple statements and use accTitle', () => {
|
||||
const result = parse(`gitGraph\n commit\n commit\n accTitle: title\n commit\n`);
|
||||
expect(result.value.$type).toBe(GitGraph);
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user