From 0082c23a903708d05fe8981221e07ed4edb86e2a Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 29 Jan 2020 19:05:51 +0100 Subject: [PATCH] #1217 Better matchingof words beginning with as as matching token AS in stateDiagram's state definition. --- docs/mermaidAPI.md | 3 +- src/diagrams/state/parser/stateDiagram.jison | 2 +- src/diagrams/state/stateDiagram.spec.js | 33 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/mermaidAPI.md b/docs/mermaidAPI.md index 7fa530406..7b7b68e06 100644 --- a/docs/mermaidAPI.md +++ b/docs/mermaidAPI.md @@ -275,11 +275,12 @@ mermaidAPI.initialize({ ### Parameters - `id` the id of the element to be rendered -- `txt` the graph definition +- `_txt` - `cb` callback which is called after rendering is finished with the svg code as inparam. - `container` selector to element in which a div with the graph temporarily will be inserted. In one is provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is completed. +- `txt` the graph definition ## diff --git a/src/diagrams/state/parser/stateDiagram.jison b/src/diagrams/state/parser/stateDiagram.jison index a5ad58cf9..49d1200c8 100644 --- a/src/diagrams/state/parser/stateDiagram.jison +++ b/src/diagrams/state/parser/stateDiagram.jison @@ -48,7 +48,7 @@ .*"[[fork]]" {this.popState();yytext=yytext.slice(0,-8).trim();/*console.warn('Fork Fork: ',yytext);*/return 'FORK';} .*"[[join]]" {this.popState();yytext=yytext.slice(0,-8).trim();/*console.warn('Fork Join: ',yytext);*/return 'JOIN';} ["] this.begin("STATE_STRING"); -"as"\s* {this.popState();this.pushState('STATE_ID');return "AS";} +\s*"as"\s+ {this.popState();this.pushState('STATE_ID');return "AS";} [^\n\{]* {this.popState();/* console.log('STATE_ID', yytext);*/return "ID";} ["] this.popState(); [^"]* { /*console.log('Long description:', yytext);*/return "STATE_DESCR";} diff --git a/src/diagrams/state/stateDiagram.spec.js b/src/diagrams/state/stateDiagram.spec.js index d609978ad..a261098f4 100644 --- a/src/diagrams/state/stateDiagram.spec.js +++ b/src/diagrams/state/stateDiagram.spec.js @@ -53,6 +53,39 @@ describe('state diagram, ', function() { parser.parse(str); }); + + it('handle "as" in state names', function() { + const str = `stateDiagram + assemble + state assemble + `; + + parser.parse(str); + }); + it('handle "as" in state names 1', function() { + const str = `stateDiagram + assemble + state assemble + `; + + parser.parse(str); + }); + it('handle "as" in state names 2', function() { + const str = `stateDiagram + assembleas + state assembleas + `; + + parser.parse(str); + }); + it('handle "as" in state names 3', function() { + const str = `stateDiagram + state "as" as as + `; + + parser.parse(str); + }); + it('scale', function() { const str = `stateDiagram\n scale 350 width