From 3a8564de92a01f95a069ac0ea6e16ea08721cf13 Mon Sep 17 00:00:00 2001 From: knsv Date: Sat, 21 Sep 2019 23:19:03 -0700 Subject: [PATCH] #945 Handling of fork statements --- src/diagrams/state/parser/stateDiagram.jison | 5 ++++ src/diagrams/state/stateDiagram.spec.js | 30 ++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/diagrams/state/parser/stateDiagram.jison b/src/diagrams/state/parser/stateDiagram.jison index ad2897657..e845da13b 100644 --- a/src/diagrams/state/parser/stateDiagram.jison +++ b/src/diagrams/state/parser/stateDiagram.jison @@ -15,6 +15,7 @@ // Special states for recognizing aliases %x ID %x STATE +%x FORK_STATE %x STATE_STRING %x STATE_ID %x ALIAS @@ -37,6 +38,8 @@ \s+"width" {this.popState();} "state"\s+ { this.pushState('STATE'); } +.*"<>" {this.popState();console.log('Fork: ',yytext);return 'FORK';} +.*"<>" {this.popState();console.log('Join: ',yytext);return 'JOIN';} ["] this.begin("STATE_STRING"); "as"\s* {this.popState();this.pushState('STATE_ID');return "AS";} [^\n]* {this.popState();console.log('ID');return "ID";} @@ -114,6 +117,8 @@ statement | scale WIDTH | COMPOSIT_STATE STRUCT_START document STRUCT_STOP | STATE_DESCR AS ID + | FORK + | JOIN ; idStatement diff --git a/src/diagrams/state/stateDiagram.spec.js b/src/diagrams/state/stateDiagram.spec.js index 664d1051b..03e047eb4 100644 --- a/src/diagrams/state/stateDiagram.spec.js +++ b/src/diagrams/state/stateDiagram.spec.js @@ -151,23 +151,23 @@ describe('state diagram, ', function() { parser.parse(str); }); - // it('should handle relation definitions', function() { - // const str = `stateDiagram\n - // state fork_state <> - // [*] --> fork_state - // fork_state --> State2 - // fork_state --> State3 + it('should handle fork statements', function() { + const str = `stateDiagram\n + state fork_state <> + [*] --> fork_state + fork_state --> State2 + fork_state --> State3 - // state join_state <> - // State2 --> join_state - // State3 --> join_state - // join_state --> State4 - // State4 --> [*] - // `; + state join_state <> + State2 --> join_state + State3 --> join_state + join_state --> State4 + State4 --> [*] + `; - // parser.parse(str); - // }); - // it('should handle relation definitions', function() { + parser.parse(str); + }); + // it('should handle concurrent state', function() { // const str = `stateDiagram\n // [*] --> Active