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: {
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: ($) => ".",
},

View File

@ -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"
}
]
}
]
},

Binary file not shown.

View File

@ -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))
)