Properly handle "rest of line" statements

Closes gh-247
This commit is contained in:
Richard Gibson
2015-11-05 23:25:41 -05:00
parent 6ac0c00e30
commit 5666d5f298

View File

@@ -12,9 +12,8 @@
%options case-insensitive %options case-insensitive
%{ // A special state for grabbing text up to the first comment/newline
// Pre-lexer code can go here %x LINE
%}
%% %%
@@ -23,15 +22,17 @@
[\-][\-][x] { return 'DOTTED_CROSS';} [\-][\-][x] { return 'DOTTED_CROSS';}
[\-][>][>] { return 'SOLID_ARROW';} [\-][>][>] { return 'SOLID_ARROW';}
[\-][\-][>][>] { return 'DOTTED_ARROW';} [\-][\-][>][>] { return 'DOTTED_ARROW';}
\s+ /* skip whitespace */ \s+ /* skip all whitespace */
\#[^\n]* /* skip comments */ <LINE>((?!\n)\s)+ /* skip same-line whitespace */
\%%[^\n]* /* skip comments */ <INITIAL,LINE>\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"participant" return 'participant'; "participant" return 'participant';
"opt" return 'opt'; "loop" { this.begin('LINE'); return 'loop'; }
"loop" return 'loop'; "opt" { this.begin('LINE'); return 'opt'; }
"alt" return 'alt'; "alt" { this.begin('LINE'); return 'alt'; }
"else" return 'else'; "else" { this.begin('LINE'); return 'else'; }
"end" return 'end'; <LINE>[^#\n;]* { this.popState(); return 'restOfLine'; }
"end" return 'end';
"left of" return 'left_of'; "left of" return 'left_of';
"right of" return 'right_of'; "right of" return 'right_of';
"over" return 'over'; "over" return 'over';
@@ -78,23 +79,23 @@ statement
| signal 'NL' | signal 'NL'
| note_statement 'NL' | note_statement 'NL'
| 'title' SPACE text 'NL' | 'title' SPACE text 'NL'
| 'loop' actor document end | 'loop' restOfLine document end
{ {
$3.unshift({type: 'loopStart', loopText:$2.actor, signalType: yy.LINETYPE.LOOP_START}); $3.unshift({type: 'loopStart', loopText:$2, signalType: yy.LINETYPE.LOOP_START});
$3.push({type: 'loopEnd', loopText:$2, signalType: yy.LINETYPE.LOOP_END}); $3.push({type: 'loopEnd', loopText:$2, signalType: yy.LINETYPE.LOOP_END});
$$=$3;} $$=$3;}
| opt actor document end | opt restOfLine document end
{ {
$3.unshift({type: 'optStart', optText:$2.actor, signalType: yy.LINETYPE.OPT_START}); $3.unshift({type: 'optStart', optText:$2, signalType: yy.LINETYPE.OPT_START});
$3.push({type: 'optEnd', optText:$2.actor, signalType: yy.LINETYPE.OPT_END}); $3.push({type: 'optEnd', optText:$2, signalType: yy.LINETYPE.OPT_END});
$$=$3;} $$=$3;}
| alt actor document else actor document end | alt restOfLine document else restOfLine document end
{ {
// Alt start // Alt start
$3.unshift({type: 'altStart', altText:$2.actor, signalType: yy.LINETYPE.ALT_START}); $3.unshift({type: 'altStart', altText:$2, signalType: yy.LINETYPE.ALT_START});
// Content in alt is already in $3 // Content in alt is already in $3
// Else // Else
$3.push({type: 'else', altText:$5.actor, signalType: yy.LINETYPE.ALT_ELSE}); $3.push({type: 'else', altText:$5, signalType: yy.LINETYPE.ALT_ELSE});
// Content in other alt // Content in other alt
$3 = $3.concat($6); $3 = $3.concat($6);
// End // End
@@ -145,4 +146,4 @@ signaltype
text2: TXT {$$ = $1.substring(1).trim().replace(/\\n/gm, "\n");} ; text2: TXT {$$ = $1.substring(1).trim().replace(/\\n/gm, "\n");} ;
%% %%