Skip to content

Commit

Permalink
Merge pull request #251 from gibson042/gh-247
Browse files Browse the repository at this point in the history
Properly handle "rest of line" statements
  • Loading branch information
knsv committed Nov 6, 2015
2 parents 34209db + ec37fc8 commit ecca358
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 95 deletions.
6 changes: 3 additions & 3 deletions src/diagrams/classDiagram/classDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var funs = [];
* @param style
*/
exports.addClass = function (id) {
console.log('Adding: '+id);
log.log('Adding: '+id);
if(typeof classes.get(id) === 'undefined'){
classes.set(id, {
id:id,
Expand All @@ -46,7 +46,7 @@ module.exports.getRelations = function () {
};

exports.addRelation = function (relation) {
console.log('Adding relation: ' + JSON.stringify(relation));
log.log('Adding relation: ' + JSON.stringify(relation));
exports.addClass(relation.id1);
exports.addClass(relation.id2);

Expand Down Expand Up @@ -76,4 +76,4 @@ exports.relationType = {
EXTENSION:1,
COMPOSITION:2,
DEPENDENCY:3
};
};
59 changes: 29 additions & 30 deletions src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@

%options case-insensitive

%{
// Pre-lexer code can go here
%}
// A special state for grabbing text up to the first comment/newline
%x LINE

%%

[\n]+ return 'NL';
[\-][x] { return 'SOLID_CROSS';}
[\-][\-][x] { return 'DOTTED_CROSS';}
[\-][>][>] { return 'SOLID_ARROW';}
[\-][\-][>][>] { return 'DOTTED_ARROW';}
\s+ /* skip whitespace */
\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
[\n]+ return 'NL';
\s+ /* skip all whitespace */
<LINE>((?!\n)\s)+ /* skip same-line whitespace */
<INITIAL,LINE>\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"participant" return 'participant';
"opt" return 'opt';
"loop" return 'loop';
"alt" return 'alt';
"else" return 'else';
"end" return 'end';
"loop" { this.begin('LINE'); return 'loop'; }
"opt" { this.begin('LINE'); return 'opt'; }
"alt" { this.begin('LINE'); return 'alt'; }
"else" { this.begin('LINE'); return 'else'; }
<LINE>[^#\n;]* { this.popState(); return 'restOfLine'; }
"end" return 'end';
"left of" return 'left_of';
"right of" return 'right_of';
"over" return 'over';
Expand All @@ -40,12 +37,14 @@
"sequenceDiagram" return 'SD';
"," return ',';
";" return 'NL';
[^\->:\n,;]+ return 'ACTOR';
"->" return 'SOLID_OPEN_ARROW';
"-->" return 'DOTTED_OPEN_ARROW';
"->>" return 'SOLID_ARROW';
[^\->:\n,;]+ return 'ACTOR';
"->>" return 'SOLID_ARROW';
"-->>" return 'DOTTED_ARROW';
":"[^#\n;]+ return 'TXT';
"->" return 'SOLID_OPEN_ARROW';
"-->" return 'DOTTED_OPEN_ARROW';
\-[x] return 'SOLID_CROSS';
\-\-[x] return 'DOTTED_CROSS';
":"[^#\n;]+ return 'TXT';
<<EOF>> return 'EOF';
. return 'INVALID';

Expand Down Expand Up @@ -78,23 +77,23 @@ statement
| signal 'NL'
| note_statement '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;}
| opt actor document end
| opt restOfLine document end
{
$3.unshift({type: 'optStart', optText:$2.actor, signalType: yy.LINETYPE.OPT_START});
$3.push({type: 'optEnd', optText:$2.actor, signalType: yy.LINETYPE.OPT_END});
$3.unshift({type: 'optStart', optText:$2, signalType: yy.LINETYPE.OPT_START});
$3.push({type: 'optEnd', optText:$2, signalType: yy.LINETYPE.OPT_END});
$$=$3;}
| alt actor document else actor document end
| alt restOfLine document else restOfLine document end
{
// 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
// 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
$3 = $3.concat($6);
// End
Expand Down Expand Up @@ -145,4 +144,4 @@ signaltype

text2: TXT {$$ = $1.substring(1).trim().replace(/\\n/gm, "\n");} ;

%%
%%
Loading

0 comments on commit ecca358

Please sign in to comment.