From 981829a426f1b7ee182a263c9316dd46295075ee Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 7 Aug 2025 15:21:13 +0200 Subject: [PATCH] Updated order of lexer statements in the grammar --- .../diagrams/sequence/parser/sequenceDiagram.jison | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison b/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison index 5902f76ba..442bec590 100644 --- a/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison +++ b/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison @@ -29,11 +29,14 @@ \%%(?!\{)[^\n]* { console.log("COMMENT"); /* skip comments */ } [^\}]\%\%[^\n]* { console.log("COMMENT"); /* skip comments */ } [0-9]+(?=[ \n]+) { console.log("NUM:", yytext); return 'NUM'; } -[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=\@\{) { console.log("LEXER:ACTOR_WITH_CONFIG_OBJECT:", yytext); yytext = yytext.trim(); return 'ACTOR_WITH_CONFIG'; } -// Enhanced config handling rules +// Enhanced config handling rules - moved before other ID rules for proper precedence \@\{ { console.log("CONFIG_START"); this.begin('CONFIG'); return 'CONFIG_START'; } [^\}]+ { console.log("CONFIG_CONTENT:", yytext); return 'CONFIG_CONTENT'; } -\} { console.log("CONFIG_END"); this.popState(); return 'CONFIG_END'; } +\} { console.log("CONFIG_END"); this.popState(); this.popState(); return 'CONFIG_END'; } +// ACTOR_WITH_CONFIG rule must come before general ACTOR rule for proper precedence +[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=\@\{) { console.log("LEXER:ACTOR_WITH_CONFIG_OBJECT:", yytext); yytext = yytext.trim(); return 'ACTOR_WITH_CONFIG'; } +// General ACTOR rule - now comes after the more specific ACTOR_WITH_CONFIG rule +[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { console.log("ACTOR:", yytext); yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } "box" { console.log("BOX"); this.begin('LINE'); return 'box'; } "participant" { console.log("PARTICIPANT"); this.begin('ID'); return 'participant'; } "actor" { console.log("ACTOR_TYPE_ACTOR"); this.begin('ID'); return 'participant_actor'; } @@ -45,9 +48,6 @@ "queue" { return yy.matchAsActorOrParticipant('queue', 'participant_queue', this._input, this); } "create" { console.log("CREATE"); return 'create'; } "destroy" { console.log("DESTROY"); this.begin('ID'); return 'destroy'; } -// Updated ID rules to handle @{...} config -// [^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=\@\{) { console.log("LEXER:ACTOR_WITH_CONFIG:", yytext); yytext = yytext.trim(); return 'ACTOR_WITH_CONFIG'; } -[^\<->\->:\n,;]+?([\-]*[^\<->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { console.log("ACTOR:", yytext); yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } "as" { console.log("AS"); this.popState(); this.popState(); this.begin('LINE'); return 'AS'; } (?:) { console.log("ALIAS_END"); this.popState(); this.popState(); return 'NEWLINE'; } // // Enhanced config handling rules