mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 23:09:49 +02:00
#945 Handling recursive logn descriptions for states with quotes
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
// Special states for recognizing aliases
|
// Special states for recognizing aliases
|
||||||
%x ID
|
%x ID
|
||||||
%x STATE
|
%x STATE
|
||||||
|
%x STATE_STRING
|
||||||
|
%x STATE_ID
|
||||||
%x ALIAS
|
%x ALIAS
|
||||||
%x SCALE
|
%x SCALE
|
||||||
%x struct
|
%x struct
|
||||||
@@ -35,6 +37,11 @@
|
|||||||
<SCALE>\s+"width" {this.popState();}
|
<SCALE>\s+"width" {this.popState();}
|
||||||
|
|
||||||
<INITIAL,struct>"state"\s+ { this.pushState('STATE'); }
|
<INITIAL,struct>"state"\s+ { this.pushState('STATE'); }
|
||||||
|
<STATE>["] this.begin("STATE_STRING");
|
||||||
|
<STATE>"as"\s* {this.popState('STATE_ID');return "AS";}
|
||||||
|
<STATE_ID>[^\n] {this.popState('STATE_ID');return "ID";}
|
||||||
|
<STATE_STRING>["] this.popState();
|
||||||
|
<STATE_STRING>[^"]* { console.log('Long description:', yytext);return "STATE_DESCR";}
|
||||||
<STATE>[^\n\s\{]+ {console.log('COMPOSIT_STATE', yytext);return 'COMPOSIT_STATE';}
|
<STATE>[^\n\s\{]+ {console.log('COMPOSIT_STATE', yytext);return 'COMPOSIT_STATE';}
|
||||||
<STATE>\{ {this.popState();this.pushState('struct'); console.log('begin struct', yytext);return 'STRUCT_START';}
|
<STATE>\{ {this.popState();this.pushState('struct'); console.log('begin struct', yytext);return 'STRUCT_START';}
|
||||||
<struct>\} { console.log('Ending struct'); this.popState(); return 'STRUCT_STOP';}}
|
<struct>\} { console.log('Ending struct'); this.popState(); return 'STRUCT_STOP';}}
|
||||||
@@ -106,6 +113,7 @@ statement
|
|||||||
| HIDE_EMPTY
|
| HIDE_EMPTY
|
||||||
| scale WIDTH
|
| scale WIDTH
|
||||||
| COMPOSIT_STATE STRUCT_START document STRUCT_STOP
|
| COMPOSIT_STATE STRUCT_START document STRUCT_STOP
|
||||||
|
| STATE_DESCR AS ID
|
||||||
;
|
;
|
||||||
|
|
||||||
idStatement
|
idStatement
|
||||||
|
@@ -121,29 +121,36 @@ describe('state diagram, ', function() {
|
|||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
// it('should handle relation definitions', function() {
|
it('should handle state deifintions with separation of id', function() {
|
||||||
// const str = `stateDiagram\n
|
const str = `stateDiagram\n
|
||||||
// scale 600 width
|
state "Long state description" as state1
|
||||||
|
`;
|
||||||
|
|
||||||
// [*] --> State1
|
parser.parse(str);
|
||||||
// State1 --> State2 : Succeeded
|
});
|
||||||
// State1 --> [*] : Aborted
|
it('should State definition with quotes', function() {
|
||||||
// State2 --> State3 : Succeeded
|
const str = `stateDiagram\n
|
||||||
// State2 --> [*] : Aborted
|
scale 600 width
|
||||||
// state State3 {
|
|
||||||
// state "Accumulate Enough Data\nLong State Name" as long1
|
|
||||||
// long1 : Just a test
|
|
||||||
// [*] --> long1
|
|
||||||
// long1 --> long1 : New Data
|
|
||||||
// long1 --> ProcessData : Enough Data
|
|
||||||
// }
|
|
||||||
// State3 --> State3 : Failed
|
|
||||||
// State3 --> [*] : Succeeded / Save Result
|
|
||||||
// State3 --> [*] : Aborted
|
|
||||||
// `;
|
|
||||||
|
|
||||||
// parser.parse(str);
|
[*] --> State1
|
||||||
// });
|
State1 --> State2 : Succeeded
|
||||||
|
State1 --> [*] : Aborted
|
||||||
|
State2 --> State3 : Succeeded
|
||||||
|
State2 --> [*] : Aborted
|
||||||
|
state State3 {
|
||||||
|
state "Accumulate Enough Data\nLong State Name" as long1
|
||||||
|
long1 : Just a test
|
||||||
|
[*] --> long1
|
||||||
|
long1 --> long1 : New Data
|
||||||
|
long1 --> ProcessData : Enough Data
|
||||||
|
}
|
||||||
|
State3 --> State3 : Failed
|
||||||
|
State3 --> [*] : Succeeded / Save Result
|
||||||
|
State3 --> [*] : Aborted
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
// it('should handle relation definitions', function() {
|
// it('should handle relation definitions', function() {
|
||||||
// const str = `stateDiagram\n
|
// const str = `stateDiagram\n
|
||||||
// state fork_state <<fork>>
|
// state fork_state <<fork>>
|
||||||
|
Reference in New Issue
Block a user