mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Class diagram parsing
Fixed a class diagram parsing issue
This commit is contained in:
parent
c9854b35e2
commit
06f6e75d5a
@ -6,10 +6,7 @@
|
|||||||
|
|
||||||
/* lexical grammar */
|
/* lexical grammar */
|
||||||
%lex
|
%lex
|
||||||
%x string generic struct
|
%x string generic struct open_directive type_directive arg_directive
|
||||||
// Directive states
|
|
||||||
%x open_directive type_directive arg_directive
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
||||||
@ -17,19 +14,18 @@
|
|||||||
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
||||||
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
||||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||||
\%\%(?!\{)*[^\n]* /* skip comments */
|
\%\%(?!\{)*[^\n]*(\r?\n)+ /* skip comments */
|
||||||
[^\}]\%\%*[^\n]* /* skip comments */
|
\%\%[^\n]*(\r?\n)* /* skip comments */
|
||||||
\%\%*[^\n]*[\n]* /* do nothing */
|
(\r?\n)+ return 'NEWLINE';
|
||||||
[\n]+ return 'NEWLINE';
|
\s+ /* skip whitespace */
|
||||||
[\s]+ /* skip whitespace */
|
|
||||||
"classDiagram-v2" return 'CLASS_DIAGRAM';
|
"classDiagram-v2" return 'CLASS_DIAGRAM';
|
||||||
"classDiagram" return 'CLASS_DIAGRAM';
|
"classDiagram" return 'CLASS_DIAGRAM';
|
||||||
[\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';}
|
[{] { this.begin("struct"); /*console.log('Starting struct');*/ return 'STRUCT_START';}
|
||||||
<struct><<EOF>> return "EOF_IN_STRUCT";
|
<struct><<EOF>> return "EOF_IN_STRUCT";
|
||||||
<struct>[\{] return "OPEN_IN_STRUCT";
|
<struct>[{] return "OPEN_IN_STRUCT";
|
||||||
<struct>\} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
|
<struct>[}] { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
|
||||||
<struct>[\n] /* nothing */
|
<struct>[\n] /* nothing */
|
||||||
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
<struct>[^{}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -136,25 +132,46 @@
|
|||||||
|
|
||||||
%left '^'
|
%left '^'
|
||||||
|
|
||||||
%start mermaidDoc
|
%start start
|
||||||
|
|
||||||
%% /* language grammar */
|
%% /* language grammar */
|
||||||
|
|
||||||
mermaidDoc
|
start
|
||||||
: graphConfig
|
: mermaidDoc
|
||||||
| directive mermaidDoc
|
| directive start
|
||||||
;
|
;
|
||||||
|
|
||||||
|
mermaidDoc
|
||||||
|
: graphConfig
|
||||||
|
;
|
||||||
|
|
||||||
|
directive
|
||||||
|
: openDirective typeDirective closeDirective NEWLINE
|
||||||
|
| openDirective typeDirective ':' argDirective closeDirective NEWLINE
|
||||||
|
;
|
||||||
|
|
||||||
|
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', 'class'); }
|
||||||
|
;
|
||||||
|
|
||||||
graphConfig
|
graphConfig
|
||||||
: NEWLINE
|
: CLASS_DIAGRAM NEWLINE statements EOF
|
||||||
| graphConfig NEWLINE
|
|
||||||
| NEWLINE CLASS_DIAGRAM NEWLINE statements EOF
|
|
||||||
| CLASS_DIAGRAM NEWLINE statements EOF
|
|
||||||
;
|
;
|
||||||
|
|
||||||
statements
|
statements
|
||||||
: statement
|
: statement
|
||||||
| NEWLINE statement
|
|
||||||
| statement NEWLINE
|
| statement NEWLINE
|
||||||
| statement NEWLINE statements
|
| statement NEWLINE statements
|
||||||
;
|
;
|
||||||
@ -166,11 +183,6 @@ className
|
|||||||
| alphaNumToken GENERICTYPE { $$=$1+'~'+$2; }
|
| alphaNumToken GENERICTYPE { $$=$1+'~'+$2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
directive
|
|
||||||
: openDirective typeDirective closeDirective 'NEWLINE'
|
|
||||||
| openDirective typeDirective ':' argDirective closeDirective 'NEWLINE'
|
|
||||||
;
|
|
||||||
|
|
||||||
statement
|
statement
|
||||||
: relationStatement { yy.addRelation($1); }
|
: relationStatement { yy.addRelation($1); }
|
||||||
| relationStatement LABEL { $1.title = yy.cleanupLabel($2); yy.addRelation($1); }
|
| relationStatement LABEL { $1.title = yy.cleanupLabel($2); yy.addRelation($1); }
|
||||||
@ -242,21 +254,4 @@ textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFA
|
|||||||
textNoTagsToken: alphaNumToken | SPACE | MINUS | keywords ;
|
textNoTagsToken: alphaNumToken | SPACE | MINUS | keywords ;
|
||||||
|
|
||||||
alphaNumToken : UNICODE_TEXT | NUM | ALPHA;
|
alphaNumToken : UNICODE_TEXT | NUM | ALPHA;
|
||||||
|
|
||||||
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', 'class'); }
|
|
||||||
;
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
Loading…
x
Reference in New Issue
Block a user