mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-03 12:25:22 +01:00
fix: shifted matchAsActorOrParticipant function to sequenceDB file from sequenceDiagram.jison file
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -12,24 +12,6 @@
|
||||
|
||||
%options case-insensitive
|
||||
|
||||
%{
|
||||
function matchAsActorOrParticipant(tokenName, tokenType) {
|
||||
const ahead = this._input;
|
||||
|
||||
// Detect if an arrow or colon is coming right after the token
|
||||
const arrowLike = /^(?:\s)*(->>|-->>|->|-->|<<->>|<<-->>)/;
|
||||
const colonLike = /^\s*:/;
|
||||
|
||||
// Treat as ACTOR if database appears inline in a message (arrow or colon follows)
|
||||
if (arrowLike.test(ahead) || colonLike.test(ahead)) {
|
||||
yytext = tokenName;
|
||||
return 'ACTOR';
|
||||
}
|
||||
// Otherwise treat as a participant type declaration
|
||||
this.begin('ID');
|
||||
return tokenType;
|
||||
}
|
||||
%}
|
||||
|
||||
// Special states for recognizing aliases
|
||||
// A special state for grabbing text up to the first comment/newline
|
||||
@@ -50,12 +32,12 @@ function matchAsActorOrParticipant(tokenName, tokenType) {
|
||||
"box" { this.begin('LINE'); return 'box'; }
|
||||
"participant" { this.begin('ID'); return 'participant'; }
|
||||
"actor" { this.begin('ID'); return 'participant_actor'; }
|
||||
"boundary" { return matchAsActorOrParticipant.call(this, 'boundary', 'participant_boundary'); }
|
||||
"control" { return matchAsActorOrParticipant.call(this, 'control', 'participant_control'); }
|
||||
"entity" { return matchAsActorOrParticipant.call(this, 'entity', 'participant_entity'); }
|
||||
"database" { return matchAsActorOrParticipant.call(this, 'database', 'participant_database'); }
|
||||
"collections" { return matchAsActorOrParticipant.call(this, 'collections', 'participant_collections'); }
|
||||
"queue" { return matchAsActorOrParticipant.call(this, 'queue', 'participant_queue'); }
|
||||
"boundary" { return yy.matchAsActorOrParticipant('boundary', 'participant_boundary', this._input, this); }
|
||||
"control" { return yy.matchAsActorOrParticipant('control', 'participant_control', this._input, this); }
|
||||
"entity" { return yy.matchAsActorOrParticipant('entity', 'participant_entity', this._input, this); }
|
||||
"database" { return yy.matchAsActorOrParticipant('database', 'participant_database', this._input, this); }
|
||||
"collections" { return yy.matchAsActorOrParticipant('collections', 'participant_collections', this._input, this); }
|
||||
"queue" { return yy.matchAsActorOrParticipant('queue', 'participant_queue', this._input, this); }
|
||||
"create" return 'create';
|
||||
"destroy" { this.begin('ID'); return 'destroy'; }
|
||||
<ID>[^\<->\->:\n,;]+?([\-]*[^\<->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
||||
|
||||
@@ -107,6 +107,7 @@ export class SequenceDB implements DiagramDB {
|
||||
this.apply = this.apply.bind(this);
|
||||
this.parseBoxData = this.parseBoxData.bind(this);
|
||||
this.parseMessage = this.parseMessage.bind(this);
|
||||
this.matchAsActorOrParticipant = this.matchAsActorOrParticipant.bind(this);
|
||||
|
||||
this.clear();
|
||||
|
||||
@@ -341,6 +342,23 @@ export class SequenceDB implements DiagramDB {
|
||||
return message;
|
||||
}
|
||||
|
||||
public matchAsActorOrParticipant(
|
||||
tokenName: string,
|
||||
tokenType: string,
|
||||
inputRemainder: string,
|
||||
lexer: any
|
||||
): string {
|
||||
log.info({ tokenName });
|
||||
const arrowLike = /^\s*(->>|-->>|->|-->|<<->>|<<-->>|-x|--x|-\))/;
|
||||
const colonLike = /^\s*:/;
|
||||
|
||||
if (arrowLike.test(inputRemainder) || colonLike.test(inputRemainder)) {
|
||||
return 'ACTOR';
|
||||
}
|
||||
lexer.begin('ID'); // used the passed lexer
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
// We expect the box statement to be color first then description
|
||||
// The color can be rgb,rgba,hsl,hsla, or css code names #hex codes are not supported for now because of the way the char # is handled
|
||||
// We extract first segment as color, the rest of the line is considered as text
|
||||
|
||||
@@ -7,10 +7,16 @@ import { setConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import renderer from './sequenceRenderer.js';
|
||||
import type { MermaidConfig } from '../../config.type.js';
|
||||
|
||||
const db = new SequenceDB();
|
||||
parser.yy = {
|
||||
parseMessage: db.parseMessage.bind(db),
|
||||
matchAsActorOrParticipant: db.matchAsActorOrParticipant.bind(db),
|
||||
};
|
||||
|
||||
export const diagram: DiagramDefinition = {
|
||||
parser,
|
||||
get db() {
|
||||
return new SequenceDB();
|
||||
return db;
|
||||
},
|
||||
renderer,
|
||||
styles,
|
||||
|
||||
Reference in New Issue
Block a user