diff --git a/examples/test.txt b/examples/test.txt index 9ce0e87..82f991b 100644 --- a/examples/test.txt +++ b/examples/test.txt @@ -1,3 +1,6 @@ -foo.shape: 'oval' -foo.bar.baz.shape: oval + + +foo + +bar : Foo Bar; baz diff --git a/grammar.js b/grammar.js index c763775..6a514df 100644 --- a/grammar.js +++ b/grammar.js @@ -9,7 +9,8 @@ module.exports = grammar({ rules: { source_file: ($) => repeat($._definition), - _definition: ($) => choice($._root_attribute, $.connection, $.shape), + _definition: ($) => + choice($._end, $._root_attribute, $.connection, $.shape), connection: ($) => seq( @@ -108,8 +109,6 @@ module.exports = grammar({ _colon: ($) => seq(repeat(" "), ":", repeat(" ")), - _dash: ($) => token.immediate("-"), - _word: ($) => /[\w\d]+/, arrow: ($) => @@ -122,6 +121,8 @@ module.exports = grammar({ ) ), + _dash: ($) => token.immediate("-"), + _unquoted_string: ($) => token.immediate(/[^'"`\n;{]+/), string: ($) => @@ -132,7 +133,7 @@ module.exports = grammar({ ), _eof: ($) => choice("\n", "\0"), - _end: ($) => choice(";", $._eof), + _end: ($) => seq(repeat(" "), choice(";", $._eof)), dot: ($) => ".", }, diff --git a/src/grammar.json b/src/grammar.json index 9ac1350..18f3f3f 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -12,6 +12,10 @@ "_definition": { "type": "CHOICE", "members": [ + { + "type": "SYMBOL", + "name": "_end" + }, { "type": "SYMBOL", "name": "_root_attribute" @@ -520,13 +524,6 @@ } ] }, - "_dash": { - "type": "IMMEDIATE_TOKEN", - "content": { - "type": "STRING", - "value": "-" - } - }, "_word": { "type": "PATTERN", "value": "[\\w\\d]+" @@ -608,6 +605,13 @@ ] } }, + "_dash": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "STRING", + "value": "-" + } + }, "_unquoted_string": { "type": "IMMEDIATE_TOKEN", "content": { @@ -703,15 +707,27 @@ ] }, "_end": { - "type": "CHOICE", + "type": "SEQ", "members": [ { - "type": "STRING", - "value": ";" + "type": "REPEAT", + "content": { + "type": "STRING", + "value": " " + } }, { - "type": "SYMBOL", - "name": "_eof" + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": ";" + }, + { + "type": "SYMBOL", + "name": "_eof" + } + ] } ] }, diff --git a/src/parser.c b/src/parser.c index 6713083..f5c642d 100644 Binary files a/src/parser.c and b/src/parser.c differ diff --git a/test/corpus/shape.txt b/test/corpus/shape.txt index 71aeeae..f0c175e 100644 --- a/test/corpus/shape.txt +++ b/test/corpus/shape.txt @@ -67,3 +67,19 @@ a: Foo Bar; b: Biz Baz (shape (identifier) (label)) ) +================================================================================ +It should skip white spaces +================================================================================ + +foo + +bar : Foo Bar; baz + +-------------------------------------------------------------------------------- + +(source_file + (shape (identifier)) + (shape (identifier) (label)) + (shape (identifier)) +) +