add emptyline rule

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-06 12:40:18 +03:00
parent e7421caac0
commit bbbb253d22
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 33 additions and 38 deletions

View file

@ -8,20 +8,21 @@ module.exports = grammar({
word: ($) => $._word, word: ($) => $._word,
conflicts: ($) => [ conflicts: ($) => [
[$._identifier],
[$.identifier], [$.identifier],
[$.arrow], [$.arrow],
[$._identifier],
[$._shape_block], [$._shape_block],
[$._shape_block_definition], [$._shape_block_definition],
[$._style_attr_block], [$._style_attr_block],
[$._inner_style_attribute], [$._inner_style_attribute],
[$._emptyline],
], ],
rules: { rules: {
source_file: ($) => repeat($._definition), source_file: ($) => repeat($._definition),
_definition: ($) => _definition: ($) =>
choice(seq(spaces, $._eof), $._root_attribute, $.connection, $.shape), choice($._emptyline, $._root_attribute, $.connection, $.shape),
connection: ($) => connection: ($) =>
seq( seq(
@ -64,9 +65,7 @@ module.exports = grammar({
spaces, spaces,
"{", "{",
spaces, spaces,
repeat( repeat(choice($._emptyline, seq($._shape_block_definition, $._end))),
choice(seq(spaces, $._eof), seq($._shape_block_definition, $._end))
),
optional(seq($._shape_block_definition, optional($._end))), optional(seq($._shape_block_definition, optional($._end))),
spaces, spaces,
"}" "}"
@ -95,7 +94,7 @@ module.exports = grammar({
spaces, spaces,
"{", "{",
spaces, spaces,
repeat(choice($._eof, seq($._inner_style_attribute, $._end))), repeat(choice($._emptyline, seq($._inner_style_attribute, $._end))),
optional(seq($._inner_style_attribute, optional($._end))), optional(seq($._inner_style_attribute, optional($._end))),
spaces, spaces,
"}" "}"
@ -178,6 +177,7 @@ module.exports = grammar({
_word: ($) => /[\w\d]+/, _word: ($) => /[\w\d]+/,
_emptyline: ($) => seq(spaces, $._eof),
_eof: ($) => choice("\n", "\0"), _eof: ($) => choice("\n", "\0"),
_end: ($) => seq(spaces, choice(";", $._eof)), _end: ($) => seq(spaces, choice(";", $._eof)),
}, },

View file

@ -12,21 +12,9 @@
"_definition": { "_definition": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_eof" "name": "_emptyline"
}
]
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -297,21 +285,9 @@
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_eof" "name": "_emptyline"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -497,7 +473,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_eof" "name": "_emptyline"
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -997,6 +973,22 @@
"type": "PATTERN", "type": "PATTERN",
"value": "[\\w\\d]+" "value": "[\\w\\d]+"
}, },
"_emptyline": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
},
"_eof": { "_eof": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -1038,15 +1030,15 @@
}, },
"extras": [], "extras": [],
"conflicts": [ "conflicts": [
[
"_identifier"
],
[ [
"identifier" "identifier"
], ],
[ [
"arrow" "arrow"
], ],
[
"_identifier"
],
[ [
"_shape_block" "_shape_block"
], ],
@ -1058,6 +1050,9 @@
], ],
[ [
"_inner_style_attribute" "_inner_style_attribute"
],
[
"_emptyline"
] ]
], ],
"precedences": [], "precedences": [],

Binary file not shown.