mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 08:50:13 +02:00
Addressed all the new comment on jison
This commit is contained in:
@@ -4,22 +4,14 @@
|
|||||||
%x string
|
%x string
|
||||||
%x md_string
|
%x md_string
|
||||||
%x title
|
%x title
|
||||||
%x open_directive
|
|
||||||
%x type_directive
|
|
||||||
%x arg_directive
|
|
||||||
%x close_directive
|
|
||||||
%x acc_title
|
%x acc_title
|
||||||
%x acc_descr
|
%x acc_descr
|
||||||
%x acc_descr_multiline
|
%x acc_descr_multiline
|
||||||
%s axis_data
|
%s axis_data
|
||||||
|
%s axis_band_data
|
||||||
%s data
|
%s data
|
||||||
%s data_inner
|
%s data_inner
|
||||||
%%
|
%%
|
||||||
\%\%\{ { this.pushState('open_directive'); return 'open_directive'; }
|
|
||||||
<open_directive>((?:(?!\}\%\%)[^:.])*) { this.pushState('type_directive'); return 'type_directive'; }
|
|
||||||
<type_directive>":" { this.popState(); this.pushState('arg_directive'); return ':'; }
|
|
||||||
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
|
||||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
|
||||||
\%\%(?!\{)[^\n]* /* skip comments */
|
\%\%(?!\{)[^\n]* /* skip comments */
|
||||||
[^\}]\%\%[^\n]* /* skip comments */
|
[^\}]\%\%[^\n]* /* skip comments */
|
||||||
<axis_data>(\r?\n) { this.popState(); return 'NEWLINE'; }
|
<axis_data>(\r?\n) { this.popState(); return 'NEWLINE'; }
|
||||||
@@ -34,38 +26,37 @@
|
|||||||
"accDescr"\s*":"\s* { this.pushState("acc_descr");return 'acc_descr'; }
|
"accDescr"\s*":"\s* { this.pushState("acc_descr");return 'acc_descr'; }
|
||||||
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; }
|
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; }
|
||||||
"accDescr"\s*"{"\s* { this.pushState("acc_descr_multiline");}
|
"accDescr"\s*"{"\s* { this.pushState("acc_descr_multiline");}
|
||||||
<acc_descr_multiline>[\}] { this.popState(); }
|
<acc_descr_multiline>"{" { this.popState(); }
|
||||||
<acc_descr_multiline>[^\}]* { return "acc_descr_multiline_value"; }
|
<acc_descr_multiline>[^\}]* { return "acc_descr_multiline_value"; }
|
||||||
|
|
||||||
"xychart-beta" {return 'XYCHART';}
|
"xychart-beta" {return 'XYCHART';}
|
||||||
("vertical"|"horizontal") {return 'CHART_ORIENTATION'}
|
(?:"vertical"|"horizontal") {return 'CHART_ORIENTATION'}
|
||||||
|
|
||||||
"x-axis" { this.pushState("axis_data"); return "X_AXIS"; }
|
"x-axis" { this.pushState("axis_data"); return "X_AXIS"; }
|
||||||
"y-axis" { this.pushState("axis_data"); return "Y_AXIS"; }
|
"y-axis" { this.pushState("axis_data"); return "Y_AXIS"; }
|
||||||
<axis_data>[\[] { this.popState(); return 'SQUARE_BRACES_START'; }
|
<axis_data>"[" { this.pushState("axis_band_data"); return 'SQUARE_BRACES_START'; }
|
||||||
<axis_data>[+-]?(?:\d+(?:\.\d+)?|\.\d+) { return 'NUMBER_WITH_DECIMAL'; }
|
|
||||||
<axis_data>"-->" { return 'ARROW_DELIMITER'; }
|
<axis_data>"-->" { return 'ARROW_DELIMITER'; }
|
||||||
|
|
||||||
|
|
||||||
"line" { this.pushState("data"); return 'LINE'; }
|
"line" { this.pushState("data"); return 'LINE'; }
|
||||||
"bar" { this.pushState("data"); return 'BAR'; }
|
"bar" { this.pushState("data"); return 'BAR'; }
|
||||||
<data>[\[] { this.pushState("data_inner"); return 'SQUARE_BRACES_START'; }
|
<data>"[" { this.pushState("data_inner"); return 'SQUARE_BRACES_START'; }
|
||||||
<data_inner>[+-]?(?:\d+(?:\.\d+)?|\.\d+) { return 'NUMBER_WITH_DECIMAL';}
|
<axis_data,data_inner>[+-]?(?:\d+(?:\.\d+)?|\.\d+) { return 'NUMBER_WITH_DECIMAL'; }
|
||||||
<data_inner>[\]] { this.popState(); return 'SQUARE_BRACES_END'; }
|
<data_inner,axis_band_data>"]" { this.popState(); return 'SQUARE_BRACES_END'; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
["][`] { this.pushState("md_string");}
|
(?:"`) { this.pushState("md_string"); }
|
||||||
<md_string>[^`"]+ { return "MD_STR";}
|
<md_string>(?:(?!`\").)+ { return "MD_STR"; }
|
||||||
<md_string>[`]["] { this.popState();}
|
<md_string>(?:`") { this.popState(); }
|
||||||
["] this.pushState("string");
|
["] this.pushState("string");
|
||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<string>[^"]* return "STR";
|
<string>[^"]* return "STR";
|
||||||
|
|
||||||
|
|
||||||
[\[] return 'SQUARE_BRACES_START'
|
"[" return 'SQUARE_BRACES_START'
|
||||||
[\]] return 'SQUARE_BRACES_END'
|
"]" return 'SQUARE_BRACES_END'
|
||||||
[A-Za-z]+ return 'ALPHA';
|
[A-Za-z]+ return 'ALPHA';
|
||||||
":" return 'COLON';
|
":" return 'COLON';
|
||||||
\+ return 'PLUS';
|
\+ return 'PLUS';
|
||||||
@@ -90,7 +81,6 @@
|
|||||||
|
|
||||||
start
|
start
|
||||||
: eol start
|
: eol start
|
||||||
| directive start
|
|
||||||
| XYCHART chartConfig start
|
| XYCHART chartConfig start
|
||||||
| XYCHART start
|
| XYCHART start
|
||||||
| document
|
| document
|
||||||
@@ -117,25 +107,14 @@ statement
|
|||||||
;
|
;
|
||||||
|
|
||||||
plotData
|
plotData
|
||||||
: SQUARE_BRACES_START commaSeperateNumber SQUARE_BRACES_END { $$ = $commaSeperateNumber }
|
: SQUARE_BRACES_START commaSeparatedNumbers SQUARE_BRACES_END { $$ = $commaSeparatedNumbers }
|
||||||
;
|
;
|
||||||
|
|
||||||
commaSeperateNumber
|
commaSeparatedNumbers
|
||||||
: NUMBER_WITH_DECIMAL commaSeperateNumberValues {
|
: NUMBER_WITH_DECIMAL COMMA commaSeparatedNumbers { $$ = [Number($NUMBER_WITH_DECIMAL), ...$commaSeparatedNumbers] }
|
||||||
$commaSeperateNumberValues = $commaSeperateNumberValues || [];
|
| NUMBER_WITH_DECIMAL { $$ = [Number($NUMBER_WITH_DECIMAL)] }
|
||||||
$commaSeperateNumberValues.unshift(Number($NUMBER_WITH_DECIMAL));
|
|
||||||
$$ = $commaSeperateNumberValues
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
commaSeperateNumberValues
|
|
||||||
: COMMA NUMBER_WITH_DECIMAL commaSeperateNumberValues {
|
|
||||||
$commaSeperateNumberValues = $commaSeperateNumberValues || [];
|
|
||||||
$commaSeperateNumberValues.unshift(Number($NUMBER_WITH_DECIMAL));
|
|
||||||
$$ = $commaSeperateNumberValues
|
|
||||||
}
|
|
||||||
|;
|
|
||||||
|
|
||||||
parseXAxis
|
parseXAxis
|
||||||
: text {yy.setXAxisTitle($text);}
|
: text {yy.setXAxisTitle($text);}
|
||||||
| text bandData {yy.setXAxisTitle($text); yy.setXAxisBand($bandData);}
|
| text bandData {yy.setXAxisTitle($text); yy.setXAxisBand($bandData);}
|
||||||
@@ -143,66 +122,35 @@ parseXAxis
|
|||||||
;
|
;
|
||||||
|
|
||||||
bandData
|
bandData
|
||||||
: SQUARE_BRACES_START commaSeperateText SQUARE_BRACES_END {$$ = $commaSeperateText}
|
: SQUARE_BRACES_START commaSeparatedTexts SQUARE_BRACES_END {$$ = $commaSeparatedTexts}
|
||||||
;
|
;
|
||||||
|
|
||||||
commaSeperateText
|
commaSeparatedTexts
|
||||||
: text commaSeperateTextValues {
|
: text COMMA commaSeparatedTexts { $$ = [$text, ...$commaSeparatedTexts] }
|
||||||
$commaSeperateTextValues = $commaSeperateTextValues || [];
|
| text { $$ = [$text] }
|
||||||
$commaSeperateTextValues.unshift($text);
|
|
||||||
$$ = $commaSeperateTextValues
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
commaSeperateTextValues
|
|
||||||
: COMMA text commaSeperateTextValues {
|
|
||||||
$commaSeperateTextValues = $commaSeperateTextValues || [];
|
|
||||||
$commaSeperateTextValues.unshift($text);
|
|
||||||
$$ = $commaSeperateTextValues
|
|
||||||
}
|
|
||||||
|;
|
|
||||||
|
|
||||||
parseYAxis
|
parseYAxis
|
||||||
: text {yy.setYAxisTitle($text);}
|
: text {yy.setYAxisTitle($text);}
|
||||||
| text NUMBER_WITH_DECIMAL ARROW_DELIMITER NUMBER_WITH_DECIMAL {yy.setYAxisTitle($text); yy.setYAxisRangeData(Number($NUMBER_WITH_DECIMAL1), Number($NUMBER_WITH_DECIMAL2));}
|
| text NUMBER_WITH_DECIMAL ARROW_DELIMITER NUMBER_WITH_DECIMAL {yy.setYAxisTitle($text); yy.setYAxisRangeData(Number($NUMBER_WITH_DECIMAL1), Number($NUMBER_WITH_DECIMAL2));}
|
||||||
;
|
;
|
||||||
|
|
||||||
directive
|
|
||||||
: openDirective typeDirective closeDirective
|
|
||||||
| openDirective typeDirective ':' argDirective closeDirective
|
|
||||||
;
|
|
||||||
|
|
||||||
eol
|
eol
|
||||||
: NEWLINE
|
: NEWLINE
|
||||||
| SEMI
|
| SEMI
|
||||||
| EOF
|
| EOF
|
||||||
;
|
;
|
||||||
|
|
||||||
openDirective
|
|
||||||
: open_directive { yy.parseDirective('%%{', 'open_directive'); }
|
|
||||||
;
|
|
||||||
|
|
||||||
typeDirective
|
|
||||||
: type_directive { yy.parseDirective($1, 'type_directive'); }
|
|
||||||
;
|
|
||||||
|
|
||||||
argDirective
|
|
||||||
: arg_directive { $1 = $1.trim().replace(/'/g, '"'); yy.parseDirective($1, 'arg_directive'); }
|
|
||||||
;
|
|
||||||
|
|
||||||
closeDirective
|
|
||||||
: close_directive { yy.parseDirective('}%%', 'close_directive', 'xychart'); }
|
|
||||||
;
|
|
||||||
|
|
||||||
text: alphaNum { $$={text:$alphaNum, type: 'text'};}
|
text: alphaNum { $$={text:$alphaNum, type: 'text'};}
|
||||||
| STR { $$={text: $STR, type: 'text'};}
|
| STR { $$={text: $STR, type: 'text'};}
|
||||||
| MD_STR { $$={text: $MD_STR, type: 'markdown'};}
|
| MD_STR { $$={text: $MD_STR, type: 'markdown'};}
|
||||||
;
|
;
|
||||||
|
|
||||||
alphaNum
|
alphaNum
|
||||||
: alphaNumToken {$$=$alphaNumToken;}
|
: alphaNumToken {$$=$alphaNumToken;}
|
||||||
| alphaNum alphaNumToken {$$=$alphaNum+''+$alphaNumToken;}
|
| alphaNum alphaNumToken {$$=$alphaNum+''+$alphaNumToken;}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
alphaNumToken : AMP | NUM | ALPHA | PLUS | EQUALS | MULT | DOT | BRKT| MINUS | UNDERSCORE ;
|
alphaNumToken : AMP | NUM | ALPHA | PLUS | EQUALS | MULT | DOT | BRKT| MINUS | UNDERSCORE ;
|
||||||
|
@@ -9,7 +9,6 @@ const parserFnConstructor = (str: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const mockDB: Record<string, Mock<any, any>> = {
|
const mockDB: Record<string, Mock<any, any>> = {
|
||||||
parseDirective: vi.fn(),
|
|
||||||
setOrientation: vi.fn(),
|
setOrientation: vi.fn(),
|
||||||
setDiagramTitle: vi.fn(),
|
setDiagramTitle: vi.fn(),
|
||||||
setXAxisTitle: vi.fn(),
|
setXAxisTitle: vi.fn(),
|
||||||
@@ -54,19 +53,6 @@ describe('Testing xychart jison file', () => {
|
|||||||
expect(mockDB.setDiagramTitle).toHaveBeenCalledWith('oneLinertitle');
|
expect(mockDB.setDiagramTitle).toHaveBeenCalledWith('oneLinertitle');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to parse directive', () => {
|
|
||||||
const str =
|
|
||||||
'%%{init: {"xychart": {"chartWidth": 600, "chartHeight": 600} } }%% \n xychart-beta';
|
|
||||||
expect(parserFnConstructor(str)).not.toThrow();
|
|
||||||
expect(mockDB.parseDirective.mock.calls[0]).toEqual(['%%{', 'open_directive']);
|
|
||||||
expect(mockDB.parseDirective.mock.calls[1]).toEqual(['init', 'type_directive']);
|
|
||||||
expect(mockDB.parseDirective.mock.calls[2]).toEqual([
|
|
||||||
'{"xychart": {"chartWidth": 600, "chartHeight": 600} }',
|
|
||||||
'arg_directive',
|
|
||||||
]);
|
|
||||||
expect(mockDB.parseDirective.mock.calls[3]).toEqual(['}%%', 'close_directive', 'xychart']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parse chart orientation', () => {
|
it('parse chart orientation', () => {
|
||||||
const str = 'xychart-beta vertical';
|
const str = 'xychart-beta vertical';
|
||||||
expect(parserFnConstructor(str)).not.toThrow();
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
@@ -339,7 +325,6 @@ describe('Testing xychart jison file', () => {
|
|||||||
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' });
|
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' });
|
||||||
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' });
|
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' });
|
||||||
expect(mockDB.setBarData).toHaveBeenCalledWith({ text: '', type: 'text' }, [23, -45, 56.6]);
|
expect(mockDB.setBarData).toHaveBeenCalledWith({ text: '', type: 'text' }, [23, -45, 56.6]);
|
||||||
clearMocks();
|
|
||||||
});
|
});
|
||||||
it('parse bar should throw for unbalanced brackets', () => {
|
it('parse bar should throw for unbalanced brackets', () => {
|
||||||
let str =
|
let str =
|
||||||
|
Reference in New Issue
Block a user