diff --git a/src/grammar.ebnf b/src/grammar.ebnf index fbf01560..3bd6c7cd 100644 --- a/src/grammar.ebnf +++ b/src/grammar.ebnf @@ -9,7 +9,7 @@ document ::= statement* statement ::= - ( 'title' ':' message + ( 'title' ':'? message | 'participant' actor ('as' alias)? | 'note' ( ( 'left of' | 'right of') actor diff --git a/src/grammar.jison b/src/grammar.jison index 9746e92f..68f94cfc 100644 --- a/src/grammar.jison +++ b/src/grammar.jison @@ -11,6 +11,8 @@ // Pre-lexer code can go here %} +%x title + %% [\r\n]+ return 'NL'; @@ -21,7 +23,8 @@ "right of" return 'right_of'; "over" return 'over'; "note" return 'note'; -"title" return 'title'; +"title" { this.begin('title'); return 'title'; } +[^\r\n]+ { this.popState(); return 'MESSAGE'; } "," return ','; [^\->:,\r\n"]+ return 'ACTOR'; \"[^"]+\" return 'ACTOR'; diff --git a/test/grammar-tests.js b/test/grammar-tests.js index 18a18abf..9f86e62c 100644 --- a/test/grammar-tests.js +++ b/test/grammar-tests.js @@ -113,6 +113,8 @@ test('Dashed Open Arrow', function() { test('Titles', function() { equal(Diagram.parse('Title: title').title, 'title', 'Title'); equal(Diagram.parse('Title: line1\\nline2').title, 'line1\nline2', 'Multiline Title'); + equal(Diagram.parse('Title title').title, 'title', 'Title without colon'); + equal(Diagram.parse('Title:: title').title, ': title', 'Title with multiple colons'); }); test('Unicode', function() {