support empty lines

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-06 00:53:06 +03:00
parent 78fe65f822
commit 811520dfd4
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
5 changed files with 54 additions and 18 deletions

View file

@ -1,3 +1,6 @@
foo.shape: 'oval'
foo.bar.baz.shape: oval
foo
bar : Foo Bar; baz

View file

@ -9,7 +9,8 @@ module.exports = grammar({
rules: { rules: {
source_file: ($) => repeat($._definition), source_file: ($) => repeat($._definition),
_definition: ($) => choice($._root_attribute, $.connection, $.shape), _definition: ($) =>
choice($._end, $._root_attribute, $.connection, $.shape),
connection: ($) => connection: ($) =>
seq( seq(
@ -108,8 +109,6 @@ module.exports = grammar({
_colon: ($) => seq(repeat(" "), ":", repeat(" ")), _colon: ($) => seq(repeat(" "), ":", repeat(" ")),
_dash: ($) => token.immediate("-"),
_word: ($) => /[\w\d]+/, _word: ($) => /[\w\d]+/,
arrow: ($) => arrow: ($) =>
@ -122,6 +121,8 @@ module.exports = grammar({
) )
), ),
_dash: ($) => token.immediate("-"),
_unquoted_string: ($) => token.immediate(/[^'"`\n;{]+/), _unquoted_string: ($) => token.immediate(/[^'"`\n;{]+/),
string: ($) => string: ($) =>
@ -132,7 +133,7 @@ module.exports = grammar({
), ),
_eof: ($) => choice("\n", "\0"), _eof: ($) => choice("\n", "\0"),
_end: ($) => choice(";", $._eof), _end: ($) => seq(repeat(" "), choice(";", $._eof)),
dot: ($) => ".", dot: ($) => ".",
}, },

View file

@ -12,6 +12,10 @@
"_definition": { "_definition": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "_end"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_root_attribute" "name": "_root_attribute"
@ -520,13 +524,6 @@
} }
] ]
}, },
"_dash": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "-"
}
},
"_word": { "_word": {
"type": "PATTERN", "type": "PATTERN",
"value": "[\\w\\d]+" "value": "[\\w\\d]+"
@ -608,6 +605,13 @@
] ]
} }
}, },
"_dash": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "-"
}
},
"_unquoted_string": { "_unquoted_string": {
"type": "IMMEDIATE_TOKEN", "type": "IMMEDIATE_TOKEN",
"content": { "content": {
@ -703,15 +707,27 @@
] ]
}, },
"_end": { "_end": {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "REPEAT",
"value": ";" "content": {
"type": "STRING",
"value": " "
}
}, },
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "_eof" "members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
} }
] ]
}, },

Binary file not shown.

View file

@ -67,3 +67,19 @@ a: Foo Bar; b: Biz Baz
(shape (identifier) (label)) (shape (identifier) (label))
) )
================================================================================
It should skip white spaces
================================================================================
foo
bar : Foo Bar; baz
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier) (label))
(shape (identifier))
)