Skip to content

Commit

Permalink
5460 - improved parsing of sequenceDiagram to include markdown strings
Browse files Browse the repository at this point in the history
  • Loading branch information
darkedges committed Apr 15, 2024
1 parent 379da2b commit ecfe14a
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
%x acc_title
%x acc_descr
%x acc_descr_multiline
%x text
%x string
%x md_string
%%

[\n]+ return 'NEWLINE';
<md_string>[^`"]+ { return "MD_STR";}
<md_string>[`]["] { this.popState();}
<*>["][`] { this.begin("md_string");}
<string>[^"]+ return "STR";
<string>["] this.popState();
<*>["] this.pushState("string");
\s+ /* skip all whitespace */
<ID,ALIAS,LINE>((?!\n)\s)+ /* skip same-line whitespace */
<INITIAL,ID,ALIAS,LINE>\#[^\n]* /* skip comments */
Expand Down Expand Up @@ -73,7 +82,9 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
"off" return 'off';
"," return ',';
";" return 'NEWLINE';
[^\+\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+\->:\n,;]+)* { yytext = yytext.trim(); return 'ACTOR'; }
<text>"]" { this.popState(); return 'SQE'; }
<*>"[" { this.pushState("text"); return 'SQS'; }
([A-Za-z0-9!"\#$%&'*+\.`?\\_\/]|\-(?=[^\>\-\.])|=(?!=))+ return 'ACTOR';
"->>" return 'SOLID_ARROW';
"-->>" return 'DOTTED_ARROW';
"->" return 'SOLID_OPEN_ARROW';
Expand All @@ -83,7 +94,6 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
\-[\)] return 'SOLID_POINT';
\-\-[\)] return 'DOTTED_POINT';
":"(?:(?:no)?wrap:)?[^#\n;]+ return 'TXT';
""(?:(?:no)?wrap:)?[^#\n;]+ return 'TXT2';
"+" return '+';
"-" return '-';
<<EOF>> return 'NEWLINE';
Expand All @@ -108,17 +118,6 @@ document
| document line {$1.push($2);$$ = $1}
;

note_section
: /* empty */ { $$ = "" }
| note_section note_line {$1=$1.concat($2);$$ = $1}
;

note_line
: ACTOR { $$ = $1 }
| TXT { $$ = $1 }
| NEWLINE { }
;

line
: SPACE statement { $$ = $2 }
| statement { $$ = $1 }
Expand Down Expand Up @@ -253,9 +252,10 @@ note_statement
$2[0] = $2[0].actor;
$2[1] = $2[1].actor;
$$ = [$3, {type:'addNote', placement:yy.PLACEMENT.OVER, actor:$2.slice(0, 2), text:$4}];}
| 'note' placement actor note_section end
| 'note' placement noteStatementText
{
$$ = [$3, {type:'addNote', placement:$2, actor:$3.actor, text:yy.parseNoteStatement($4)}];}
console.log($3);
$$ = [$3, {type:'addNote', placement:$2, actor:$3.actor, text:$3.text }];}
;

links_statement
Expand Down Expand Up @@ -336,4 +336,15 @@ text2
: TXT {$$ = yy.parseMessage($1.trim().substring(1)) }
;

%%
text3
: STR
{ $$ = {text: $STR, type: 'string'};}
| MD_STR
{ $$ = {text: $MD_STR, type: 'markdown'};}
;

noteStatementText
: ACTOR SQS text3 SQE
{$$ = {actor: $ACTOR, text: $text3 }}
;
%%

0 comments on commit ecfe14a

Please sign in to comment.