chore: added logs in sequenceDiagram.jison

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
omkarht
2025-08-07 18:07:13 +05:30
parent 848f69a75c
commit 327a5aa9fd

View File

@@ -15,88 +15,99 @@
// Special states for recognizing aliases // Special states for recognizing aliases
// 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 ID ALIAS LINE %x ID ALIAS LINE CONFIG CONFIG_DATA
%x acc_title %x acc_title
%x acc_descr %x acc_descr
%x acc_descr_multiline %x acc_descr_multiline
%% %%
[\n]+ return 'NEWLINE'; [\n]+ { console.log("NEWLINE"); return 'NEWLINE'; }
\s+ /* skip all whitespace */ \s+ { console.log("WHITESPACE"); /* skip whitespace */ }
<ID,ALIAS,LINE>((?!\n)\s)+ /* skip same-line whitespace */ <ID,ALIAS,LINE>((?!\n)\s)+ { console.log("SAME-LINE-WHITESPACE"); /* skip same-line whitespace */ }
<INITIAL,ID,ALIAS,LINE>\#[^\n]* /* skip comments */ <INITIAL,ID,ALIAS,LINE>\#[^\n]* { console.log("COMMENT"); /* skip comments */ }
\%%(?!\{)[^\n]* /* skip comments */ \%%(?!\{)[^\n]* { console.log("COMMENT"); /* skip comments */ }
[^\}]\%\%[^\n]* /* skip comments */ [^\}]\%\%[^\n]* { console.log("COMMENT"); /* skip comments */ }
[0-9]+(?=[ \n]+) return 'NUM'; [0-9]+(?=[ \n]+) { console.log("NUM:", yytext); return 'NUM'; }
"box" { this.begin('LINE'); return 'box'; } <ID>[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=\@\{) { console.log("LEXER:ACTOR_WITH_CONFIG_OBJECT:", yytext); yytext = yytext.trim(); return 'ACTOR_WITH_CONFIG'; }
"participant" { this.begin('ID'); return 'participant'; } // Enhanced config handling rules
"actor" { this.begin('ID'); return 'participant_actor'; } <ID>\@\{ { console.log("CONFIG_START"); this.begin('CONFIG'); return 'CONFIG_START'; }
<CONFIG>[^\}]+ { console.log("CONFIG_CONTENT:", yytext); return 'CONFIG_CONTENT'; }
<CONFIG>\} { console.log("CONFIG_END"); this.popState(); return 'CONFIG_END'; }
"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'; }
"boundary" { return yy.matchAsActorOrParticipant('boundary', 'participant_boundary', this._input, this); } "boundary" { return yy.matchAsActorOrParticipant('boundary', 'participant_boundary', this._input, this); }
"control" { return yy.matchAsActorOrParticipant('control', 'participant_control', this._input, this); } "control" { return yy.matchAsActorOrParticipant('control', 'participant_control', this._input, this); }
"entity" { return yy.matchAsActorOrParticipant('entity', 'participant_entity', this._input, this); } "entity" { return yy.matchAsActorOrParticipant('entity', 'participant_entity', this._input, this); }
"database" { return yy.matchAsActorOrParticipant('database', 'participant_database', this._input, this); } "database" { return yy.matchAsActorOrParticipant('database', 'participant_database', this._input, this); }
"collections" { return yy.matchAsActorOrParticipant('collections', 'participant_collections', this._input, this); } "collections" { return yy.matchAsActorOrParticipant('collections', 'participant_collections', this._input, this); }
"queue" { return yy.matchAsActorOrParticipant('queue', 'participant_queue', this._input, this); } "queue" { return yy.matchAsActorOrParticipant('queue', 'participant_queue', this._input, this); }
"create" return 'create'; "create" { console.log("CREATE"); return 'create'; }
"destroy" { this.begin('ID'); return 'destroy'; } "destroy" { console.log("DESTROY"); this.begin('ID'); return 'destroy'; }
<ID>[^\<->\->:\n,;]+?([\-]*[^\<->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } // Updated ID rules to handle @{...} config
<ALIAS>"as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; } // <ID>[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=\@\{) { console.log("LEXER:ACTOR_WITH_CONFIG:", yytext); yytext = yytext.trim(); return 'ACTOR_WITH_CONFIG'; }
<ALIAS>(?:) { this.popState(); this.popState(); return 'NEWLINE'; } <ID>[^\<->\->:\n,;]+?([\-]*[^\<->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { console.log("ACTOR:", yytext); yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
"loop" { this.begin('LINE'); return 'loop'; } <ALIAS>"as" { console.log("AS"); this.popState(); this.popState(); this.begin('LINE'); return 'AS'; }
"rect" { this.begin('LINE'); return 'rect'; } <ALIAS>(?:) { console.log("ALIAS_END"); this.popState(); this.popState(); return 'NEWLINE'; }
"opt" { this.begin('LINE'); return 'opt'; } // // Enhanced config handling rules
"alt" { this.begin('LINE'); return 'alt'; } // <ID>\@\{ { console.log("CONFIG_START"); this.begin('CONFIG'); return 'CONFIG_START'; }
"else" { this.begin('LINE'); return 'else'; } // <CONFIG>[^\}]+ { console.log("CONFIG_CONTENT:", yytext); return 'CONFIG_CONTENT'; }
"par" { this.begin('LINE'); return 'par'; } // <CONFIG>\} { console.log("CONFIG_END"); this.popState(); return 'CONFIG_END'; }
"par_over" { this.begin('LINE'); return 'par_over'; } "loop" { console.log("LOOP"); this.begin('LINE'); return 'loop'; }
"and" { this.begin('LINE'); return 'and'; } "rect" { console.log("RECT"); this.begin('LINE'); return 'rect'; }
"critical" { this.begin('LINE'); return 'critical'; } "opt" { console.log("OPT"); this.begin('LINE'); return 'opt'; }
"option" { this.begin('LINE'); return 'option'; } "alt" { console.log("ALT"); this.begin('LINE'); return 'alt'; }
"break" { this.begin('LINE'); return 'break'; } "else" { console.log("ELSE"); this.begin('LINE'); return 'else'; }
<LINE>(?:[:]?(?:no)?wrap:)?[^#\n;]* { this.popState(); return 'restOfLine'; } "par" { console.log("PAR"); this.begin('LINE'); return 'par'; }
"end" return 'end'; "par_over" { console.log("PAR_OVER"); this.begin('LINE'); return 'par_over'; }
"left of" return 'left_of'; "and" { console.log("AND"); this.begin('LINE'); return 'and'; }
"right of" return 'right_of'; "critical" { console.log("CRITICAL"); this.begin('LINE'); return 'critical'; }
"links" return 'links'; "option" { console.log("OPTION"); this.begin('LINE'); return 'option'; }
"link" return 'link'; "break" { console.log("BREAK"); this.begin('LINE'); return 'break'; }
"properties" return 'properties'; <LINE>(?:[:]?(?:no)?wrap:)?[^#\n;]* { console.log("REST_OF_LINE:", yytext); this.popState(); return 'restOfLine'; }
"details" return 'details'; "end" { console.log("END"); return 'end'; }
"over" return 'over'; "left of" { console.log("LEFT_OF"); return 'left_of'; }
"note" return 'note'; "right of" { console.log("RIGHT_OF"); return 'right_of'; }
"activate" { this.begin('ID'); return 'activate'; } "links" { console.log("LINKS"); return 'links'; }
"deactivate" { this.begin('ID'); return 'deactivate'; } "link" { console.log("LINK"); return 'link'; }
"title"\s[^#\n;]+ return 'title'; "properties" { console.log("PROPERTIES"); return 'properties'; }
"title:"\s[^#\n;]+ return 'legacy_title'; "details" { console.log("DETAILS"); return 'details'; }
accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; } "over" { console.log("OVER"); return 'over'; }
<acc_title>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; } "note" { console.log("NOTE"); return 'note'; }
accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; } "activate" { console.log("ACTIVATE"); this.begin('ID'); return 'activate'; }
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; } "deactivate" { console.log("DEACTIVATE"); this.begin('ID'); return 'deactivate'; }
accDescr\s*"{"\s* { this.begin("acc_descr_multiline");} "title"\s[^#\n;]+ { console.log("TITLE"); return 'title'; }
<acc_descr_multiline>[\}] { this.popState(); } "title:"\s[^#\n;]+ { console.log("LEGACY_TITLE"); return 'legacy_title'; }
<acc_descr_multiline>[^\}]* return "acc_descr_multiline_value"; accTitle\s*":"\s* { console.log("ACC_TITLE"); this.begin("acc_title"); return 'acc_title'; }
"sequenceDiagram" return 'SD'; <acc_title>(?!\n|;|#)*[^\n]* { console.log("ACC_TITLE_VALUE:", yytext); this.popState(); return "acc_title_value"; }
"autonumber" return 'autonumber'; accDescr\s*":"\s* { console.log("ACC_DESCR"); this.begin("acc_descr"); return 'acc_descr'; }
"off" return 'off'; <acc_descr>(?!\n|;|#)*[^\n]* { console.log("ACC_DESCR_VALUE:", yytext); this.popState(); return "acc_descr_value"; }
"," return ','; accDescr\s*"{"\s* { console.log("ACC_DESCR_MULTILINE_START"); this.begin("acc_descr_multiline"); }
";" return 'NEWLINE'; <acc_descr_multiline>[\}] { console.log("ACC_DESCR_MULTILINE_END"); this.popState(); }
[^\+\<->\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+\<->\->:\n,;]+)* { yytext = yytext.trim(); return 'ACTOR'; } <acc_descr_multiline>[^\}]* { console.log("ACC_DESCR_MULTILINE_VALUE:", yytext); return "acc_descr_multiline_value"; }
"->>" return 'SOLID_ARROW'; "sequenceDiagram" { console.log("SEQUENCE_DIAGRAM"); return 'SD'; }
"<<->>" return 'BIDIRECTIONAL_SOLID_ARROW'; "autonumber" { console.log("AUTONUMBER"); return 'autonumber'; }
"-->>" return 'DOTTED_ARROW'; "off" { console.log("OFF"); return 'off'; }
"<<-->>" return 'BIDIRECTIONAL_DOTTED_ARROW'; "," { console.log("COMMA"); return ','; }
"->" return 'SOLID_OPEN_ARROW'; ";" { console.log("SEMICOLON"); return 'NEWLINE'; }
"-->" return 'DOTTED_OPEN_ARROW'; [^\+\<->\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+\<->\->:\n,;]+)* { console.log("ACTOR_GENERIC:", yytext); yytext = yytext.trim(); return 'ACTOR'; }
\-[x] return 'SOLID_CROSS'; "->>" { console.log("SOLID_ARROW"); return 'SOLID_ARROW'; }
\-\-[x] return 'DOTTED_CROSS'; "<<->>" { console.log("BIDIRECTIONAL_SOLID_ARROW"); return 'BIDIRECTIONAL_SOLID_ARROW'; }
\-[\)] return 'SOLID_POINT'; "-->>" { console.log("DOTTED_ARROW"); return 'DOTTED_ARROW'; }
\-\-[\)] return 'DOTTED_POINT'; "<<-->>" { console.log("BIDIRECTIONAL_DOTTED_ARROW"); return 'BIDIRECTIONAL_DOTTED_ARROW'; }
":"(?:(?:no)?wrap:)?[^#\n;]* return 'TXT'; "->" { console.log("SOLID_OPEN_ARROW"); return 'SOLID_OPEN_ARROW'; }
":" return 'TXT'; "-->" { console.log("DOTTED_OPEN_ARROW"); return 'DOTTED_OPEN_ARROW'; }
"+" return '+'; \-[x] { console.log("SOLID_CROSS"); return 'SOLID_CROSS'; }
"-" return '-'; \-\-[x] { console.log("DOTTED_CROSS"); return 'DOTTED_CROSS'; }
<<EOF>> return 'NEWLINE'; \-[\)] { console.log("SOLID_POINT"); return 'SOLID_POINT'; }
. return 'INVALID'; \-\-[\)] { console.log("DOTTED_POINT"); return 'DOTTED_POINT'; }
":"(?:(?:no)?wrap:)?[^#\n;]* { console.log("TEXT_WITH_WRAP:", yytext); return 'TXT'; }
":" { console.log("TEXT"); return 'TXT'; }
"+" { console.log("PLUS"); return '+'; }
"-" { console.log("MINUS"); return '-'; }
<<EOF>> { console.log("EOF"); return 'NEWLINE'; }
. { console.log("INVALID:", yytext); return 'INVALID'; }
/lex /lex
@@ -233,12 +244,39 @@ else_sections
; ;
participant_statement participant_statement
: 'participant' actor 'AS' restOfLine 'NEWLINE' {$2.draw='participant'; $2.type='addParticipant';$2.description=yy.parseMessage($4); $$=$2;} : 'participant' actor_with_config 'AS' restOfLine 'NEWLINE'
| 'participant' actor 'NEWLINE' {$2.draw='participant'; $2.type='addParticipant';$$=$2;} {
| 'participant_actor' actor 'AS' restOfLine 'NEWLINE' {$2.draw='actor'; $2.type='addParticipant';$2.description=yy.parseMessage($4); $$=$2;} console.log('Participant with config and alias:', $2, $4);
| 'participant_actor' actor 'NEWLINE' {$2.draw='actor'; $2.type='addParticipant'; $$=$2;} $2.draw = 'participant';
| 'destroy' actor 'NEWLINE' {$2.type='destroyParticipant'; $$=$2;} $2.type = 'addParticipant';
$2.description = yy.parseMessage($4);
$$ = $2;
}
| 'participant' actor_with_config 'NEWLINE'
{
console.log('Participant with config without alias:', $2);
$2.draw = 'participant';
$2.type = 'addParticipant';
$$ = $2;
}
| 'participant_actor' actor_with_config 'AS' restOfLine 'NEWLINE'
{
$2.draw = 'actor';
$2.type = 'addParticipant';
$2.description = yy.parseMessage($4);
$$ = $2;
}
| 'participant_actor' actor_with_config 'NEWLINE'
{
$2.draw = 'actor';
$2.type = 'addParticipant';
$$ = $2;
}
| 'destroy' actor 'NEWLINE'
{
$2.type = 'destroyParticipant';
$$ = $2;
}
| 'participant_boundary' actor 'AS' restOfLine 'NEWLINE' {$2.draw='boundary'; $2.type='addParticipant';$2.description=yy.parseMessage($4); $$=$2;} | 'participant_boundary' actor 'AS' restOfLine 'NEWLINE' {$2.draw='boundary'; $2.type='addParticipant';$2.description=yy.parseMessage($4); $$=$2;}
| 'participant_boundary' actor 'NEWLINE' {$2.draw='boundary'; $2.type='addParticipant'; $$=$2;} | 'participant_boundary' actor 'NEWLINE' {$2.draw='boundary'; $2.type='addParticipant'; $$=$2;}
@@ -327,13 +365,71 @@ 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}]}
; ;
// actor actor_with_config
// : actor_participant : ACTOR_WITH_CONFIG config_object // Changed from ACTOR
// | actor_actor {
// ; console.log("ACTOR_WITH_CONFIG Actor with config:", $1, $2);
$$ = {
type: 'addParticipant',
actor: $1,
config: $2
};
}
| ACTOR config_object
{
console.log("Actor with config:", $1, $2);
$$ = {
type: 'addParticipant',
actor: $1,
config: $2
};
}
| ACTOR
{
console.log("Actor without config:", $1);
$$ = {
type: 'addParticipant',
actor: $1,
};
}
;
actor: ACTOR {$$={ type: 'addParticipant', actor:$1}}; config_object
// actor_actor: ACTOR {$$={type: 'addActor', actor:$1}}; : CONFIG_START CONFIG_CONTENT CONFIG_END
{
console.log("Parsing config content:", $2);
try {
// Remove any trailing whitespace/newlines
const content = $2.trim();
$$ = JSON.parse(content);
console.log("Successfully parsed JSON config:", $$);
} catch (e) {
console.log("JSON parse failed, using raw content");
$$ = $2.trim();
}
}
;
actor
: ACTOR_WITH_CONFIG // Add this case
{
console.log("Actor with config flag:", $1);
$$ = { type: 'addParticipant', actor: $1 };
}
| actor config_object
{
console.log("Actor with config:", $1, $2);
$$ = {
type: 'addParticipant',
actor: $1.actor,
config: $2
};
}
| ACTOR
{
console.log("Basic actor:", $1);
$$ = { type: 'addParticipant', actor: $1 };
}
;
signaltype signaltype
: SOLID_OPEN_ARROW { $$ = yy.LINETYPE.SOLID_OPEN; } : SOLID_OPEN_ARROW { $$ = yy.LINETYPE.SOLID_OPEN; }