From 6f054519e7c4eb81f9223df9e7bd4da4d425d6a4 Mon Sep 17 00:00:00 2001 From: knsv Date: Sat, 21 Sep 2019 08:50:32 -0700 Subject: [PATCH] #945 Handling simple state statements --- src/diagrams/state/parser/stateDiagram.jison | 33 +++++++++++++------- src/diagrams/state/stateDiagram.spec.js | 21 +++++++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/diagrams/state/parser/stateDiagram.jison b/src/diagrams/state/parser/stateDiagram.jison index cfdb61158..880c274a1 100644 --- a/src/diagrams/state/parser/stateDiagram.jison +++ b/src/diagrams/state/parser/stateDiagram.jison @@ -14,8 +14,10 @@ // Special states for recognizing aliases %x ID +%x STATE %x ALIAS %x SCALE +%x struct // A special state for grabbing text up to the first comment/newline %x LINE @@ -24,16 +26,23 @@ [\n]+ return 'NL'; \s+ /* skip all whitespace */ -((?!\n)\s)+ /* skip same-line whitespace */ -\#[^\n]* /* skip comments */ +((?!\n)\s)+ /* skip same-line whitespace */ +\#[^\n]* /* skip comments */ \%%[^\n]* /* skip comments */ "scale"\s+ { this.pushState('SCALE'); console.log('Got scale', yytext);return 'scale'; } \d+ return 'WIDTH'; \s+"width" {this.popState();} -"state"\s+ { this.begin('LINE'); return 'state'; } -"note"\s+ { this.begin('LINE'); return 'note'; } +"state"\s+ { this.pushState('STATE'); } +[^\n\s\{]+ {console.log('COMPOSIT_STATE', yytext);return 'COMPOSIT_STATE';} +\{ {this.popState();this.pushState('struct'); console.log('begin struct', yytext);return 'STRUCT_START';} +\} { console.log('Ending struct'); this.popState(); return 'STRUCT_STOP';}} +[\n] /* nothing */ +// [^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";} + + +"note"\s+ { this.begin('LINE'); return 'note'; } "stateDiagram"\s+ { console.log('Got state diagram', yytext,'#');return 'SD'; } "hide empty description" { console.log('HIDE_EMPTY', yytext,'#');return 'HIDE_EMPTY'; } // "participant" { this.begin('ID'); return 'participant'; } @@ -45,11 +54,11 @@ // "and" { this.begin('LINE'); return 'and'; } // [^#\n;]* { this.popState(); return 'restOfLine'; } // "end" return 'end'; -"[*]" { console.log('EDGE_STATE=',yytext); return 'EDGE_STATE';} -[^:\n\s\-]+ { console.log('ID=',yytext); return 'ID';} -\s*":"[^\+\->:\n,;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; } -"left of" return 'left_of'; -"right of" return 'right_of'; +"[*]" { console.log('EDGE_STATE=',yytext); return 'EDGE_STATE';} +[^:\n\s\-]+ { console.log('ID=',yytext); return 'ID';} +\s*":"[^\+\->:\n,;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; } +"left of" return 'left_of'; +"right of" return 'right_of'; // "over" return 'over'; // "note" return 'note'; // "activate" { this.begin('ID'); return 'activate'; } @@ -59,7 +68,7 @@ // "," return ','; // ";" return 'NL'; // [^\+\->:\n,;]+ { yytext = yytext.trim(); return 'ACTOR'; } -"-->" return '-->'; +"-->" return '-->'; // "--" return '--'; // ":"[^#\n;]+ return 'TXT'; <> return 'NL'; @@ -86,15 +95,17 @@ document line : SPACE statement { console.log('here');$$ = $2 } - | statement {console.log('there'); $$ = $1 } + | statement {console.log('line', $1); $$ = $1 } | NL { $$=[];} ; statement : idStatement DESCR | idStatement '-->' idStatement + | idStatement '-->' idStatement DESCR | HIDE_EMPTY | scale WIDTH + | COMPOSIT_STATE STRUCT_START document STRUCT_STOP ; idStatement diff --git a/src/diagrams/state/stateDiagram.spec.js b/src/diagrams/state/stateDiagram.spec.js index e17cb3dee..1a0b92a31 100644 --- a/src/diagrams/state/stateDiagram.spec.js +++ b/src/diagrams/state/stateDiagram.spec.js @@ -59,6 +59,27 @@ describe('state diagram, ', function() { parser.parse(str); }); + it('description after second state', function() { + const str = `stateDiagram\n + scale 350 width + [*] --> State1 : This is the description + State1 --> [*] + `; + + parser.parse(str); + }); + it('should handle state statements', function() { + const str = `stateDiagram\n + state Configuring { + [*] --> NewValueSelection + NewValueSelection --> NewValuePreview : EvNewValue + NewValuePreview --> NewValueSelection : EvNewValueRejected + NewValuePreview --> NewValueSelection : EvNewValueSaved1 + } + `; + + parser.parse(str); + }); xit('should handle relation definitions', function() { const str = `stateDiagram\n state Configuring {