fix multi inline shape attrs

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-05 00:26:24 +03:00
parent 2bd0ded807
commit 975e4c299a
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 125 additions and 116 deletions

View file

@ -1,3 +1,3 @@
Foo Bar -- Biz Baz
-Bar-Foo- <- -Baz-Biz-
foo.shape: 'oval'
foo.bar.baz.shape: oval

View file

@ -7,18 +7,13 @@ module.exports = grammar({
// TODO: add the actual grammar rules
source_file: ($) => repeat($._definition),
_definition: ($) =>
choice(
choice($._root_attribute, $._shape_attribute),
$.connection,
$.shape
),
_definition: ($) => choice($._root_attribute, $.connection, $.shape),
connection: ($) =>
seq(
$.identifier,
choice(
seq(seq($.arrow, $.identifier, ":", $.label)),
seq(seq($.arrow, $.identifier, $._colon, $.label)),
seq(repeat1(seq($.arrow, $.identifier)))
),
$._end
@ -28,7 +23,10 @@ module.exports = grammar({
seq(
$.identifier,
repeat(seq($.dot, $.identifier)),
optional(seq(":", $.label)),
choice(
optional(seq($.dot, $._shape_attribute)),
optional(seq($._colon, $.label))
),
$._end
),
@ -39,12 +37,7 @@ module.exports = grammar({
attr_value: ($) => choice($.string, $._unquoted_string),
_root_attribute: ($) =>
seq(
alias($._root_attr_key, $.attr_key),
":",
alias($.label, $.attr_value),
$._end
),
seq(alias($._root_attr_key, $.attr_key), $._colon, $.attr_value, $._end),
_root_attr_key: ($) => "direction",
@ -53,19 +46,14 @@ module.exports = grammar({
alias("style", $.attr_key),
$.dot,
alias($._style_attr_key, $.attr_key),
":",
$.attr_value,
$._end
$._colon,
$.attr_value
),
_shape_attribute: ($) =>
seq(
$.identifier,
$.dot,
choice(
seq(alias($._shape_attr_key, $.attr_key), ":", $.attr_value, $._end),
seq(alias($._shape_attr_key, $.attr_key), $._colon, $.attr_value),
$._style_attribute
)
),
_shape_attr_key: ($) =>
@ -114,6 +102,8 @@ module.exports = grammar({
)
),
_colon: ($) => seq(repeat(" "), ":", repeat(" ")),
_dash: ($) => token.immediate("-"),
_word: ($) => /[\w\d]+/,
@ -128,13 +118,13 @@ module.exports = grammar({
)
),
_unquoted_string: ($) => /[^\n;{]+/,
_unquoted_string: ($) => token.immediate(/[^'"`\n;{]+/),
string: ($) =>
choice(
seq("'", repeat(token(/[^'\n]+/)), "'"),
seq('"', repeat(token(/[^'\n]+/)), '"'),
seq("`", repeat(token(/[^'\n]+/)), "`")
seq("'", repeat(token.immediate(/[^'\n]+/)), "'"),
seq('"', repeat(token.immediate(/[^"\n]+/)), '"'),
seq("`", repeat(token.immediate(/[^`\n]+/)), "`")
),
_end: ($) => choice(";", "\n", "\0"),

View file

@ -10,21 +10,12 @@
}
},
"_definition": {
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_root_attribute"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
{
"type": "SYMBOL",
"name": "connection"
@ -60,8 +51,8 @@
"name": "identifier"
},
{
"type": "STRING",
"value": ":"
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "SYMBOL",
@ -123,6 +114,9 @@
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
@ -130,8 +124,29 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "SYMBOL",
@ -143,6 +158,8 @@
"type": "BLANK"
}
]
}
]
},
{
"type": "SYMBOL",
@ -193,17 +210,12 @@
"value": "attr_key"
},
{
"type": "STRING",
"value": ":"
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "label"
},
"named": true,
"value": "attr_value"
"name": "attr_value"
},
{
"type": "SYMBOL",
@ -241,31 +253,16 @@
"value": "attr_key"
},
{
"type": "STRING",
"value": ":"
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "SYMBOL",
"name": "attr_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
},
"_shape_attribute": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "CHOICE",
"members": [
{
@ -281,16 +278,12 @@
"value": "attr_key"
},
{
"type": "STRING",
"value": ":"
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "SYMBOL",
"name": "attr_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
},
@ -299,8 +292,6 @@
"name": "_style_attribute"
}
]
}
]
},
"_shape_attr_key": {
"type": "CHOICE",
@ -489,6 +480,29 @@
]
}
},
"_colon": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
}
]
},
"_dash": {
"type": "IMMEDIATE_TOKEN",
"content": {
@ -578,8 +592,11 @@
}
},
"_unquoted_string": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[^\\n;{]+"
"value": "[^'\"`\\n;{]+"
}
},
"string": {
"type": "CHOICE",
@ -594,7 +611,7 @@
{
"type": "REPEAT",
"content": {
"type": "TOKEN",
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[^'\\n]+"
@ -617,10 +634,10 @@
{
"type": "REPEAT",
"content": {
"type": "TOKEN",
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[^'\\n]+"
"value": "[^\"\\n]+"
}
}
},
@ -640,10 +657,10 @@
{
"type": "REPEAT",
"content": {
"type": "TOKEN",
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[^'\\n]+"
"value": "[^`\\n]+"
}
}
},

View file

@ -75,6 +75,14 @@
"multiple": true,
"required": true,
"types": [
{
"type": "attr_key",
"named": true
},
{
"type": "attr_value",
"named": true
},
{
"type": "dot",
"named": true
@ -110,14 +118,6 @@
"type": "connection",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "shape",
"named": true

Binary file not shown.

View file

@ -15,11 +15,13 @@ Inline shape attribute
==================
foo.shape: oval
foo.bar.baz.shape: oval
---
(source_file
(identifier) (dot) (attr_key) (attr_value)
(shape (identifier) (dot) (attr_key) (attr_value))
(shape (identifier) (dot) (identifier) (dot) (identifier) (dot) (attr_key) (attr_value))
)
==================
@ -31,7 +33,7 @@ foo.style.opacity: 5
---
(source_file
(identifier) (dot) (attr_key) (dot) (attr_key) (attr_value)
(shape (identifier) (dot) (attr_key) (dot) (attr_key) (attr_value))
)