Skip to content

Commit

Permalink
Changes to timeline.jison
Browse files Browse the repository at this point in the history
1. Removed the semicolon from the regex for titles, sections, periods, and events.
Changes to timeline.spec.js
1. Added a test for the changes made in the timeline parser
  • Loading branch information
FutzMonitor committed Feb 27, 2024
1 parent 70c8a3d commit 1169cb9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/mermaid/src/diagrams/timeline/parser/timeline.jison
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
\#[^\n]* /* skip comments */

"timeline" return 'timeline';
"title"\s[^#\n;]+ return 'title';
"title"\s[^#\n]+ return 'title';
accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; }
<acc_title>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; }
accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; }
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; }
accDescr\s*"{"\s* { this.begin("acc_descr_multiline");}
<acc_descr_multiline>[\}] { this.popState(); }
<acc_descr_multiline>[^\}]* return "acc_descr_multiline_value";
"section"\s[^#:\n;]+ return 'section';
"section"\s[^#:\n]+ return 'section';

// event starting with "==>" keyword
":"\s[^#:\n;]+ return 'event';
[^#:\n;]+ return 'period';
":"\s[^#:\n]+ return 'event';
[^#:\n]+ return 'period';


<<EOF>> return 'EOF';
Expand Down
25 changes: 25 additions & 0 deletions packages/mermaid/src/diagrams/timeline/timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,30 @@ describe('when parsing a timeline ', function () {
}
});
});

it('TL-6 should handle a section, and task and its multi line events with semicolons', function () {
let str = `timeline
section ;a;bc-123;
;ta;sk1;: ;ev;ent1;
;tas;k2;: ;eve;nt2;: ;event;3;
: ;eve;nt4: ;even;t5;
`;
timeline.parse(str);
expect(timelineDB.getSections()[0]).to.deep.equal(';a;bc-123;');
timelineDB.getTasks().forEach((t) => {
switch (t.task.trim()) {
case ';ta;sk1;':
expect(t.events).to.deep.equal([';ev;ent1;']);
break;

case ';tas;k2;':
expect(t.events).to.deep.equal([';eve;nt2;', ';event;3;', ';eve;nt4', ';even;t5;']);
break;

default:
break;
}
});
});
});
});

0 comments on commit 1169cb9

Please sign in to comment.