Skip to content

Commit 187882b

Browse files
committed
Add support for WebSequenceDiagrams title syntax
In WebSequenceDiagrams, title messages aren't delimited by a :. This adds support for that using an exclusive start condition in the JISON grammar, while preserving backwards compatibility. I also added a couple tests.
1 parent 78e00d3 commit 187882b

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Diff for: src/grammar.ebnf

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
document ::= statement*
1010

1111
statement ::=
12-
( 'title' ':' message
12+
( 'title' ':'? message
1313
| 'participant' actor ('as' alias)?
1414
| 'note' (
1515
( 'left of' | 'right of') actor

Diff for: src/grammar.jison

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// Pre-lexer code can go here
1212
%}
1313

14+
%x title
15+
1416
%%
1517

1618
[\r\n]+ return 'NL';
@@ -21,7 +23,8 @@
2123
"right of" return 'right_of';
2224
"over" return 'over';
2325
"note" return 'note';
24-
"title" return 'title';
26+
"title" { this.begin('title'); return 'title'; }
27+
<title>[^\r\n]+ { this.popState(); return 'MESSAGE'; }
2528
"," return ',';
2629
[^\->:,\r\n"]+ return 'ACTOR';
2730
\"[^"]+\" return 'ACTOR';

Diff for: test/grammar-tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ test('Dashed Open Arrow', function() {
113113
test('Titles', function() {
114114
equal(Diagram.parse('Title: title').title, 'title', 'Title');
115115
equal(Diagram.parse('Title: line1\\nline2').title, 'line1\nline2', 'Multiline Title');
116+
equal(Diagram.parse('Title title').title, 'title', 'Title without colon');
117+
equal(Diagram.parse('Title:: title').title, ': title', 'Title with multiple colons');
116118
});
117119

118120
test('Unicode', function() {

0 commit comments

Comments
 (0)