Merge pull request #3762 from avijit1258/bug/3728_comments_not_ignored_composite_states

comments in states are skipped now
This commit is contained in:
Knut Sveidqvist
2022-11-18 10:45:01 +01:00
committed by GitHub
2 changed files with 22 additions and 0 deletions

View File

@@ -184,6 +184,27 @@ describe('ClassDefs and classes when parsing a State diagram', () => {
});
});
});
describe('comments parsing', () => {
it('working inside states', function () {
let diagram = '';
diagram += 'stateDiagram-v2\n\n';
diagram += '[*] --> Moving\n';
diagram += 'Moving --> Still\n';
diagram += 'Moving --> Crash\n';
diagram += 'state Moving {\n';
diagram += '%% comment inside state\n';
diagram += 'slow --> fast\n';
diagram += '}\n';
stateDiagram.parser.parse(diagram);
stateDiagram.parser.yy.extract(stateDiagram.parser.yy.getRootDocV2());
const states = stateDiagram.parser.yy.getStates();
expect(states['Moving'].doc.length).toEqual(1);
});
});
});
});
});

View File

@@ -109,6 +109,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
<STATE>[^\n\s\{]+ {/*console.log('COMPOSIT_STATE', yytext);*/return 'COMPOSIT_STATE';}
<STATE>\n {this.popState();}
<INITIAL,STATE>\{ {this.popState();this.pushState('struct'); /*console.log('begin struct', yytext);*/return 'STRUCT_START';}
<struct>\%\%(?!\{)[^\n]* /* skip comments inside state*/
<struct>\} { /*console.log('Ending struct');*/ this.popState(); return 'STRUCT_STOP';}}
<struct>[\n] /* nothing */