mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Allow sequenceDiagram participant aliasing
Fixes gh-263
This commit is contained in:
parent
69ce29841d
commit
b42939796c
@ -12,17 +12,24 @@
|
|||||||
|
|
||||||
%options case-insensitive
|
%options case-insensitive
|
||||||
|
|
||||||
|
// Special states for recognizing aliases
|
||||||
|
%x ID
|
||||||
|
%x ALIAS
|
||||||
|
|
||||||
// A special state for grabbing text up to the first comment/newline
|
// A special state for grabbing text up to the first comment/newline
|
||||||
%x LINE
|
%x LINE
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
[\n]+ return 'NL';
|
[\n]+ return 'NL';
|
||||||
\s+ /* skip all whitespace */
|
\s+ /* skip all whitespace */
|
||||||
<LINE>((?!\n)\s)+ /* skip same-line whitespace */
|
<ID,ALIAS,LINE>((?!\n)\s)+ /* skip same-line whitespace */
|
||||||
<INITIAL,LINE>\#[^\n]* /* skip comments */
|
<INITIAL,ID,ALIAS,LINE>\#[^\n]* /* skip comments */
|
||||||
\%%[^\n]* /* skip comments */
|
\%%[^\n]* /* skip comments */
|
||||||
"participant" return 'participant';
|
"participant" { this.begin('ID'); return 'participant'; }
|
||||||
|
<ID>[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { this.begin('ALIAS'); return 'ACTOR'; }
|
||||||
|
<ALIAS>"as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; }
|
||||||
|
<ALIAS>(?:) { this.popState(); this.popState(); return 'NL'; }
|
||||||
"loop" { this.begin('LINE'); return 'loop'; }
|
"loop" { this.begin('LINE'); return 'loop'; }
|
||||||
"opt" { this.begin('LINE'); return 'opt'; }
|
"opt" { this.begin('LINE'); return 'opt'; }
|
||||||
"alt" { this.begin('LINE'); return 'alt'; }
|
"alt" { this.begin('LINE'); return 'alt'; }
|
||||||
@ -72,7 +79,8 @@ line
|
|||||||
;
|
;
|
||||||
|
|
||||||
statement
|
statement
|
||||||
: 'participant' actor 'NL' {$$=$2;}
|
: 'participant' actor 'AS' restOfLine 'NL' {$2.description=$4; $$=$2;}
|
||||||
|
| 'participant' actor 'NL' {$$=$2;}
|
||||||
| signal 'NL'
|
| signal 'NL'
|
||||||
| note_statement 'NL'
|
| note_statement 'NL'
|
||||||
| 'title' SPACE text 'NL'
|
| 'title' SPACE text 'NL'
|
||||||
@ -133,9 +141,6 @@ signal
|
|||||||
{$$ = [$1,$3,{type: 'addMessage', from:$1.actor, to:$3.actor, signalType:$2, msg:$4}]}
|
{$$ = [$1,$3,{type: 'addMessage', from:$1.actor, to:$3.actor, signalType:$2, msg:$4}]}
|
||||||
;
|
;
|
||||||
|
|
||||||
actors: actors actor
|
|
||||||
| actor
|
|
||||||
;
|
|
||||||
actor
|
actor
|
||||||
: ACTOR {$$={type: 'addActor', actor:$1}}
|
: ACTOR {$$={type: 'addActor', actor:$1}}
|
||||||
;
|
;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
* Created by knut on 14-11-19.
|
* Created by knut on 14-11-19.
|
||||||
*/
|
*/
|
||||||
var actors = {};
|
var actors = {};
|
||||||
var actorKeys = [];
|
|
||||||
var messages = [];
|
var messages = [];
|
||||||
var notes = [];
|
var notes = [];
|
||||||
var Logger = require('../../logger');
|
var Logger = require('../../logger');
|
||||||
@ -11,8 +10,14 @@ var log = new Logger.Log();
|
|||||||
|
|
||||||
|
|
||||||
exports.addActor = function(id,name,description){
|
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};
|
actors[id] = {name:name, description:description};
|
||||||
actorKeys.push(id);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.addMessage = function(idFrom, idTo, message, answer){
|
exports.addMessage = function(idFrom, idTo, message, answer){
|
||||||
@ -98,7 +103,7 @@ exports.apply = function(param){
|
|||||||
// log.debug(param);
|
// log.debug(param);
|
||||||
switch(param.type){
|
switch(param.type){
|
||||||
case 'addActor':
|
case 'addActor':
|
||||||
exports.addActor(param.actor, param.actor, param.actor);
|
exports.addActor(param.actor, param.actor, param.description);
|
||||||
break;
|
break;
|
||||||
case 'addNote':
|
case 'addNote':
|
||||||
exports.addNote(param.actor,param.placement, param.text);
|
exports.addNote(param.actor,param.placement, param.text);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user