fix parsing single-line block

Closes #11
This commit is contained in:
Dmitriy Pleshevskiy 2022-12-13 16:41:34 +03:00
parent 9e60a469c5
commit 7a053d6bf1
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 261 additions and 68 deletions

View file

@ -28,7 +28,12 @@ module.exports = grammar({
$.block_comment,
],
conflicts: ($) => [[$._connection_path, $.container]],
conflicts: ($) => [
[$._connection_path, $.container],
[$._container_block],
[$._connection_block],
[$._style_attribute_block],
],
rules: {
source_file: ($) => repeat($._root_definition),
@ -70,10 +75,12 @@ module.exports = grammar({
),
_connection_block: ($) =>
seq("{", repeat($._connection_block_definition), "}"),
_connection_block_definition: ($) =>
choice($._eol, seq($._connection_attribute, $._end)),
seq(
"{",
repeat(choice($._eol, seq($._connection_attribute, $._end))),
optional(seq($._connection_attribute, optional($._end))),
"}"
),
// containers
@ -93,16 +100,15 @@ module.exports = grammar({
),
_container_block: ($) =>
seq("{", repeat($._container_block_definition), "}"),
seq(
"{",
repeat(choice($._eol, seq($._container_block_definition, $._end))),
optional(seq($._container_block_definition, optional($._end))),
"}"
),
_container_block_definition: ($) =>
choice(
$._eol,
seq(
choice($.shape, $.container, $.connection, $._shape_attribute),
$._end
)
),
choice($.shape, $.container, $.connection, $._shape_attribute),
// shapes
@ -212,6 +218,9 @@ module.exports = grammar({
seq(alias($._inner_style_attribute, $.attribute), $._end)
)
),
optional(
seq(alias($._inner_style_attribute, $.attribute), optional($._end))
),
"}"
),

View file

@ -194,38 +194,63 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_connection_block_definition"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_connection_attribute"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_connection_attribute"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"_connection_block_definition": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_connection_attribute"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
},
"container": {
"type": "PREC",
"value": 2,
@ -337,10 +362,57 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_container_block_definition"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_container_block_definition"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_container_block_definition"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
@ -352,37 +424,19 @@
"members": [
{
"type": "SYMBOL",
"name": "_eol"
"name": "shape"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "shape"
},
{
"type": "SYMBOL",
"name": "container"
},
{
"type": "SYMBOL",
"name": "connection"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
{
"type": "SYMBOL",
"name": "_end"
}
]
"type": "SYMBOL",
"name": "container"
},
{
"type": "SYMBOL",
"name": "connection"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
@ -832,6 +886,40 @@
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_inner_style_attribute"
},
"named": true,
"value": "attribute"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
@ -1403,6 +1491,15 @@
[
"_connection_path",
"container"
],
[
"_container_block"
],
[
"_connection_block"
],
[
"_style_attribute_block"
]
],
"precedences": [],

Binary file not shown.

View file

@ -301,6 +301,31 @@ foo -> bar: {
)
)
================================================================================
Define attributes for connection in single-line
================================================================================
foo -> bar: {source-arrowhead: 0; target-arrowhead: 1}
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key)
(arrow)
(shape_key)
(block
(attribute
(attr_key)
(label)
)
(attribute
(attr_key)
(label)
)
)
)
)
================================================================================
Block style attributes inside a connection arrowhead
================================================================================
@ -392,4 +417,23 @@ foo -> bar: {
)
)
================================================================================
Declire style attributes in single-line
================================================================================
foo.style: {opacity: 0.5; fill: red}
--------------------------------------------------------------------------------
(source_file
(shape
(shape_key) (dot)
(attribute
(attr_key)
(block
(attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value))
)
)
)
)

View file

@ -224,3 +224,46 @@ Foo: Baz {
)
)
)
================================================================================
Declare shapes in a container in single-line (Issue #11)
================================================================================
primty: Primitive types {
Never: {"!"}
Boolean: {bool}
Textual: {char; str}
}
--------------------------------------------------------------------------------
(source_file
(container
(container_key)
(label)
(block
(container
(container_key)
(block
(shape
(shape_key (string (string_fragment)))
)
)
)
(container
(container_key)
(block
(shape (shape_key))
)
)
(container
(container_key)
(block
(shape (shape_key))
(shape (shape_key))
)
)
)
)
)

Binary file not shown.