Comment handling

This commit is contained in:
knsv
2015-03-22 17:51:13 +01:00
parent 3781dea498
commit 22b9ee4919

View File

@@ -8,6 +8,7 @@
%lex %lex
%% %%
\%\%[^\n]* {console.log('comment: '+yytext)}
"style" return 'STYLE'; "style" return 'STYLE';
"default" return 'DEFAULT'; "default" return 'DEFAULT';
"linkStyle" return 'LINKSTYLE'; "linkStyle" return 'LINKSTYLE';
@@ -128,7 +129,7 @@
"{" return 'DIAMOND_START' "{" return 'DIAMOND_START'
"}" return 'DIAMOND_STOP' "}" return 'DIAMOND_STOP'
"\"" return 'QUOTE'; "\"" return 'QUOTE';
\n return 'NEWLINE'; \n+ return 'NEWLINE';
\s return 'SPACE'; \s return 'SPACE';
<<EOF>> return 'EOF'; <<EOF>> return 'EOF';
@@ -142,7 +143,7 @@
%% /* language grammar */ %% /* language grammar */
mermaidDoc: graphConfig document ; mermaidDoc: graphConfig document;
document document
: /* empty */ : /* empty */
@@ -165,7 +166,9 @@ line
; ;
graphConfig graphConfig
: GRAPH SPACE DIR FirstStmtSeperator : SPACE graphConfig
| NEWLINE graphConfig
| GRAPH SPACE DIR FirstStmtSeperator
{ yy.setDirection($3);$$ = $3;} { yy.setDirection($3);$$ = $3;}
| GRAPH SPACE TAGEND FirstStmtSeperator | GRAPH SPACE TAGEND FirstStmtSeperator
{ yy.setDirection("LR");$$ = $3;} { yy.setDirection("LR");$$ = $3;}
@@ -177,6 +180,12 @@ graphConfig
{ yy.setDirection("TB");$$ = $3;} { yy.setDirection("TB");$$ = $3;}
; ;
ending: endToken ending
| endToken
;
endToken: NEWLINE | SPACE | EOF;
FirstStmtSeperator FirstStmtSeperator
: SEMI | NEWLINE | spaceList NEWLINE ; : SEMI | NEWLINE | spaceList NEWLINE ;
@@ -195,9 +204,7 @@ spaceList
; ;
statement statement
: commentStatement NEWLINE : verticeStatement separator
{$$=[];}
| verticeStatement separator
{$$=$1} {$$=$1}
| styleStatement separator | styleStatement separator
{$$=[];} {$$=[];}
@@ -219,11 +226,11 @@ endStatement: end
| SPACE endStatement | SPACE endStatement
; ;
separator: NEWLINE | SEMI | EOF ; separator: NEWLINE {console.log('nl sep')} | SEMI {console.log('semi sep')}| EOF {console.log('eof sep')};
verticeStatement: verticeStatement:
vertex link vertex vertex link vertex
{ yy.addLink($1,$3,$2);$$ = [$1,$3];} { console.log($3);yy.addLink($1,$3,$2);$$ = [$1,$3];}
| vertex | vertex
{$$ = [$1];} {$$ = [$1];}
; ;
@@ -274,28 +281,6 @@ alphaNumStatement
{$$=$1+'-'+$3;} {$$=$1+'-'+$3;}
; ;
linkOld: linkStatement arrowText
{$1.text = $2;$$ = $1;}
| linkStatement arrowText SPACE
{$1.text = $2;$$ = $1;}
| linkStatement
{$$ = $1;}
| linkStatement SPACE
{$$ = $1;}
| '--' text linkStatement
{$5.text = $3;$$ = $5;}
| '--' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
| '-.' SPACE text SPACE linkStatement
{$5.text = $3;$$ = $5;}
| '-.' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
| '==' SPACE text SPACE linkStatement
{$5.text = $3;$$ = $5;}
| '==' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
;
link: linkStatement arrowText link: linkStatement arrowText
{$1.text = $2;$$ = $1;} {$1.text = $2;$$ = $1;}
| linkStatement arrowText SPACE | linkStatement arrowText SPACE