diff --git a/src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison b/src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison index 2af34f4ec..47cbea8e9 100644 --- a/src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison +++ b/src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison @@ -12,17 +12,24 @@ %options case-insensitive +// Special states for recognizing aliases +%x ID +%x ALIAS + // A special state for grabbing text up to the first comment/newline %x LINE %% -[\n]+ return 'NL'; -\s+ /* skip all whitespace */ -((?!\n)\s)+ /* skip same-line whitespace */ -\#[^\n]* /* skip comments */ -\%%[^\n]* /* skip comments */ -"participant" return 'participant'; +[\n]+ return 'NL'; +\s+ /* skip all whitespace */ +((?!\n)\s)+ /* skip same-line whitespace */ +\#[^\n]* /* skip comments */ +\%%[^\n]* /* skip comments */ +"participant" { this.begin('ID'); return 'participant'; } +[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { this.begin('ALIAS'); return 'ACTOR'; } +"as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; } +(?:) { this.popState(); this.popState(); return 'NL'; } "loop" { this.begin('LINE'); return 'loop'; } "opt" { this.begin('LINE'); return 'opt'; } "alt" { this.begin('LINE'); return 'alt'; } @@ -72,7 +79,8 @@ line ; statement - : 'participant' actor 'NL' {$$=$2;} + : 'participant' actor 'AS' restOfLine 'NL' {$2.description=$4; $$=$2;} + | 'participant' actor 'NL' {$$=$2;} | signal 'NL' | note_statement 'NL' | 'title' SPACE text 'NL' @@ -133,9 +141,6 @@ signal {$$ = [$1,$3,{type: 'addMessage', from:$1.actor, to:$3.actor, signalType:$2, msg:$4}]} ; -actors: actors actor - | actor - ; actor : ACTOR {$$={type: 'addActor', actor:$1}} ; diff --git a/src/diagrams/sequenceDiagram/sequenceDb.js b/src/diagrams/sequenceDiagram/sequenceDb.js index 284315bd0..e924bd684 100644 --- a/src/diagrams/sequenceDiagram/sequenceDb.js +++ b/src/diagrams/sequenceDiagram/sequenceDb.js @@ -2,7 +2,6 @@ * Created by knut on 14-11-19. */ var actors = {}; -var actorKeys = []; var messages = []; var notes = []; var Logger = require('../../logger'); @@ -11,8 +10,14 @@ var log = new Logger.Log(); exports.addActor = function(id,name,description){ + // Don't allow description nulling + var old = actors[id]; + if ( old && name === old.name && description == null ) return; + + // Don't allow null descriptions, either + if ( description == null ) description = name; + actors[id] = {name:name, description:description}; - actorKeys.push(id); }; exports.addMessage = function(idFrom, idTo, message, answer){ @@ -98,7 +103,7 @@ exports.apply = function(param){ // log.debug(param); switch(param.type){ case 'addActor': - exports.addActor(param.actor, param.actor, param.actor); + exports.addActor(param.actor, param.actor, param.description); break; case 'addNote': exports.addNote(param.actor,param.placement, param.text);