2019-09-21 08:19:55 -07:00
|
|
|
/** mermaid
|
|
|
|
* https://mermaidjs.github.io/
|
|
|
|
* (c) 2014-2015 Knut Sveidqvist
|
|
|
|
* MIT license.
|
|
|
|
*
|
|
|
|
* Based on js sequence diagrams jison grammr
|
|
|
|
* http://bramp.github.io/js-sequence-diagrams/
|
|
|
|
* (c) 2012-2013 Andrew Brampton (bramp.net)
|
|
|
|
* Simplified BSD license.
|
|
|
|
*/
|
|
|
|
%lex
|
|
|
|
|
|
|
|
%options case-insensitive
|
|
|
|
|
|
|
|
// Special states for recognizing aliases
|
|
|
|
%x ID
|
2019-09-21 08:50:32 -07:00
|
|
|
%x STATE
|
2019-09-21 23:19:03 -07:00
|
|
|
%x FORK_STATE
|
2019-09-21 09:12:02 -07:00
|
|
|
%x STATE_STRING
|
|
|
|
%x STATE_ID
|
2019-09-21 08:19:55 -07:00
|
|
|
%x ALIAS
|
|
|
|
%x SCALE
|
2019-09-22 02:38:04 -07:00
|
|
|
%x NOTE
|
|
|
|
%x NOTE_ID
|
|
|
|
%x NOTE_TEXT
|
2019-09-22 03:30:36 -07:00
|
|
|
%x FLOATING_NOTE
|
|
|
|
%x FLOATING_NOTE_ID
|
2019-09-21 08:50:32 -07:00
|
|
|
%x struct
|
2019-09-21 08:19:55 -07:00
|
|
|
|
|
|
|
// A special state for grabbing text up to the first comment/newline
|
|
|
|
%x LINE
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
[\n]+ return 'NL';
|
|
|
|
\s+ /* skip all whitespace */
|
2019-09-21 08:50:32 -07:00
|
|
|
<ID,STATE,struct,LINE>((?!\n)\s)+ /* skip same-line whitespace */
|
|
|
|
<INITIAL,ID,STATE,struct,LINE>\#[^\n]* /* skip comments */
|
2019-09-21 08:19:55 -07:00
|
|
|
\%%[^\n]* /* skip comments */
|
|
|
|
|
2019-10-06 16:06:15 +02:00
|
|
|
"scale"\s+ { this.pushState('SCALE'); /* console.log('Got scale', yytext);*/ return 'scale'; }
|
2019-09-21 08:19:55 -07:00
|
|
|
<SCALE>\d+ return 'WIDTH';
|
|
|
|
<SCALE>\s+"width" {this.popState();}
|
|
|
|
|
2019-09-21 08:54:18 -07:00
|
|
|
<INITIAL,struct>"state"\s+ { this.pushState('STATE'); }
|
2019-10-06 14:11:17 +02:00
|
|
|
<STATE>.*"<<fork>>" {this.popState();yytext=yytext.slice(0,-8).trim(); console.warn('Fork Fork: ',yytext);return 'FORK';}
|
|
|
|
<STATE>.*"<<join>>" {this.popState();yytext=yytext.slice(0,-8).trim();console.warn('Fork Join: ',yytext);return 'JOIN';}
|
|
|
|
<STATE>.*"[[fork]]" {this.popState();yytext=yytext.slice(0,-8).trim();console.warn('Fork Fork: ',yytext);return 'FORK';}
|
|
|
|
<STATE>.*"[[join]]" {this.popState();yytext=yytext.slice(0,-8).trim();console.warn('Fork Join: ',yytext);return 'JOIN';}
|
2019-09-21 09:12:02 -07:00
|
|
|
<STATE>["] this.begin("STATE_STRING");
|
2019-09-21 11:31:09 -07:00
|
|
|
<STATE>"as"\s* {this.popState();this.pushState('STATE_ID');return "AS";}
|
2019-10-06 16:06:15 +02:00
|
|
|
<STATE_ID>[^\n\{]* {this.popState();/* console.log('STATE_ID', yytext);*/return "ID";}
|
2019-09-21 09:12:02 -07:00
|
|
|
<STATE_STRING>["] this.popState();
|
2019-10-06 16:06:15 +02:00
|
|
|
<STATE_STRING>[^"]* { /*console.log('Long description:', yytext);*/return "STATE_DESCR";}
|
|
|
|
<STATE>[^\n\s\{]+ {/*console.log('COMPOSIT_STATE', yytext);*/return 'COMPOSIT_STATE';}
|
2019-09-22 03:30:36 -07:00
|
|
|
<STATE>\n {this.popState();}
|
2019-10-06 16:06:15 +02:00
|
|
|
<INITIAL,STATE>\{ {this.popState();this.pushState('struct'); /*console.log('begin struct', yytext);*/return 'STRUCT_START';}
|
|
|
|
<struct>\} { /*console.log('Ending struct');*/ this.popState(); return 'STRUCT_STOP';}}
|
2019-09-21 08:50:32 -07:00
|
|
|
<struct>[\n] /* nothing */
|
|
|
|
|
2019-09-22 02:38:04 -07:00
|
|
|
<INITIAL,struct>"note"\s+ { this.begin('NOTE'); return 'note'; }
|
2019-10-06 16:06:15 +02:00
|
|
|
<NOTE>"left of" { this.popState();this.pushState('NOTE_ID');return 'left_of';}
|
2019-09-22 02:38:04 -07:00
|
|
|
<NOTE>"right of" { this.popState();this.pushState('NOTE_ID');return 'right_of';}
|
2019-09-22 03:30:36 -07:00
|
|
|
<NOTE>\" { this.popState();this.pushState('FLOATING_NOTE');}
|
|
|
|
<FLOATING_NOTE>\s*"as"\s* {this.popState();this.pushState('FLOATING_NOTE_ID');return "AS";}
|
|
|
|
<FLOATING_NOTE>["] /**/
|
2019-10-06 16:06:15 +02:00
|
|
|
<FLOATING_NOTE>[^"]* { /*console.log('Floating note text: ', yytext);*/return "NOTE_TEXT";}
|
|
|
|
<FLOATING_NOTE_ID>[^\n]* {this.popState();/*console.log('Floating note ID', yytext);*/return "ID";}
|
|
|
|
<NOTE_ID>\s*[^:\n\s\-]+ { this.popState();this.pushState('NOTE_TEXT');/*console.log('Got ID for note', yytext);*/return 'ID';}
|
|
|
|
<NOTE_TEXT>\s*":"[^:\n;]+ { this.popState();/*console.log('Got NOTE_TEXT for note',yytext);*/yytext = yytext.substr(2).trim();return 'NOTE_TEXT';}
|
|
|
|
<NOTE_TEXT>\s*[^:;]+"end note" { this.popState();/*console.log('Got NOTE_TEXT for note',yytext);*/yytext = yytext.slice(0,-8).trim();return 'NOTE_TEXT';}
|
|
|
|
|
|
|
|
"stateDiagram"\s+ { /*console.log('Got state diagram', yytext,'#');*/return 'SD'; }
|
|
|
|
"hide empty description" { /*console.log('HIDE_EMPTY', yytext,'#');*/return 'HIDE_EMPTY'; }
|
|
|
|
<INITIAL,struct>"[*]" { /*console.log('EDGE_STATE=',yytext);*/ return 'EDGE_STATE';}
|
|
|
|
<INITIAL,struct>[^:\n\s\-\{]+ { /*console.log('=>ID=',yytext);*/ return 'ID';}
|
|
|
|
// <INITIAL,struct>\s*":"[^\+\->:\n;]+ { yytext = yytext.trim(); /*console.log('Descr = ', yytext);*/ return 'DESCR'; }
|
|
|
|
<INITIAL,struct>\s*":"[^:\n;]+ { yytext = yytext.trim(); /*console.log('Descr = ', yytext);*/ return 'DESCR'; }
|
2019-09-21 08:50:32 -07:00
|
|
|
<INITIAL,struct>"-->" return '-->';
|
2019-09-22 02:38:04 -07:00
|
|
|
<struct>"--" return 'CONCURRENT';
|
2019-09-21 08:19:55 -07:00
|
|
|
<<EOF>> return 'NL';
|
|
|
|
. return 'INVALID';
|
|
|
|
|
|
|
|
/lex
|
|
|
|
|
|
|
|
%left '^'
|
|
|
|
|
|
|
|
%start start
|
|
|
|
|
|
|
|
%% /* language grammar */
|
|
|
|
|
|
|
|
start
|
|
|
|
: SPACE start
|
|
|
|
| NL start
|
2019-10-06 16:06:15 +02:00
|
|
|
| SD document { /*console.warn('Root document', $2);*/ yy.setRootDoc($2);return $2; }
|
2019-09-21 08:19:55 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
document
|
|
|
|
: /* empty */ { $$ = [] }
|
2019-10-02 19:32:13 +02:00
|
|
|
| document line {
|
|
|
|
if($2!='nl'){
|
|
|
|
$1.push($2);$$ = $1
|
|
|
|
}
|
2019-10-03 19:08:15 +02:00
|
|
|
// console.warn('Got document',$1, $2);
|
2019-10-02 19:32:13 +02:00
|
|
|
}
|
2019-09-21 08:19:55 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
line
|
2019-10-03 19:08:15 +02:00
|
|
|
: SPACE statement { $$ = $2 }
|
|
|
|
| statement { $$ = $1 }
|
|
|
|
| NL { $$='nl';}
|
2019-09-21 08:19:55 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
statement
|
2019-10-06 16:06:15 +02:00
|
|
|
: idStatement DESCR { /*console.warn('got id and descr', $1, $2.trim());*/$$={ stmt: 'state', id: $1, type: 'default', description: $2.trim()};}
|
2019-10-02 19:32:13 +02:00
|
|
|
| idStatement '-->' idStatement
|
|
|
|
{
|
|
|
|
/*console.warn('got id', $1);yy.addRelation($1, $3);*/
|
|
|
|
$$={ stmt: 'relation', state1: { stmt: 'state', id: $1, type: 'default', description: '' }, state2:{ stmt: 'state', id: $3 ,type: 'default', description: ''}};
|
|
|
|
}
|
|
|
|
| idStatement '-->' idStatement DESCR
|
|
|
|
{
|
|
|
|
/*yy.addRelation($1, $3, $4.substr(1).trim());*/
|
|
|
|
$$={ stmt: 'relation', state1: { stmt: 'state', id: $1, type: 'default', description: '' }, state2:{ stmt: 'state', id: $3 ,type: 'default', description: ''}, description: $4.substr(1).trim()};
|
|
|
|
}
|
2019-09-21 08:19:55 -07:00
|
|
|
| HIDE_EMPTY
|
|
|
|
| scale WIDTH
|
2019-09-22 03:30:36 -07:00
|
|
|
| COMPOSIT_STATE
|
2019-09-21 08:50:32 -07:00
|
|
|
| COMPOSIT_STATE STRUCT_START document STRUCT_STOP
|
2019-10-02 19:32:13 +02:00
|
|
|
{
|
2019-10-06 16:06:15 +02:00
|
|
|
/* console.warn('Adding document for state without id ', $1);*/
|
2019-10-03 19:08:15 +02:00
|
|
|
$$={ stmt: 'state', id: $1, type: 'default', description: '', doc: $3 }
|
2019-10-02 19:32:13 +02:00
|
|
|
}
|
|
|
|
| STATE_DESCR AS ID { $$={id: $3, type: 'default', description: $1.trim()};}
|
2019-09-22 03:30:36 -07:00
|
|
|
| STATE_DESCR AS ID STRUCT_START document STRUCT_STOP
|
2019-10-02 19:32:13 +02:00
|
|
|
{
|
|
|
|
//console.warn('Adding document for state with id ', $3, $4); yy.addDocument($3);
|
|
|
|
$$={ stmt: 'state', id: $3, type: 'default', description: $1, doc: $5 }
|
|
|
|
}
|
2019-10-06 14:11:17 +02:00
|
|
|
| FORK {
|
|
|
|
$$={ stmt: 'state', id: $1, type: 'fork' }
|
|
|
|
}
|
|
|
|
| JOIN {
|
|
|
|
$$={ stmt: 'state', id: $1, type: 'join' }
|
|
|
|
}
|
2019-10-06 15:44:31 +02:00
|
|
|
| CONCURRENT {
|
|
|
|
$$={ stmt: 'state', id: yy.getDividerId(), type: 'divider' }
|
|
|
|
}
|
2019-09-22 02:38:04 -07:00
|
|
|
| note notePosition ID NOTE_TEXT
|
2019-10-06 10:52:37 +02:00
|
|
|
{
|
2019-10-06 16:06:15 +02:00
|
|
|
/*console.warn('got NOTE, position: ', $2.trim(), 'id = ', $3.trim(), 'note: ', $4);*/
|
2019-10-06 10:52:37 +02:00
|
|
|
$$={ stmt: 'state', id: $3.trim(), note:{position: $2.trim(), text: $4.trim()}};
|
|
|
|
}
|
2019-09-22 03:30:36 -07:00
|
|
|
| note NOTE_TEXT AS ID
|
2019-09-21 08:19:55 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
idStatement
|
2019-09-25 21:29:32 +02:00
|
|
|
: ID {$$=$1;}
|
|
|
|
| EDGE_STATE {$$=$1;}
|
2019-09-21 08:19:55 -07:00
|
|
|
;
|
2019-09-22 02:38:04 -07:00
|
|
|
|
|
|
|
notePosition
|
|
|
|
: left_of
|
|
|
|
| right_of
|
|
|
|
;
|
2019-09-21 08:19:55 -07:00
|
|
|
|
|
|
|
%%
|