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

View file

@ -194,17 +194,6 @@
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL",
"name": "_connection_block_definition"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_connection_block_definition": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -225,6 +214,42 @@
] ]
} }
] ]
}
},
{
"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": "}"
}
]
}, },
"container": { "container": {
"type": "PREC", "type": "PREC",
@ -337,17 +362,6 @@
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL",
"name": "_container_block_definition"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_container_block_definition": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -358,6 +372,54 @@
"type": "SEQ", "type": "SEQ",
"members": [ "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": "}"
}
]
},
"_container_block_definition": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -378,14 +440,6 @@
} }
] ]
}, },
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
},
"shape": { "shape": {
"type": "PREC", "type": "PREC",
"value": 3, "value": 3,
@ -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", "type": "STRING",
"value": "}" "value": "}"
@ -1403,6 +1491,15 @@
[ [
"_connection_path", "_connection_path",
"container" "container"
],
[
"_container_block"
],
[
"_connection_block"
],
[
"_style_attribute_block"
] ]
], ],
"precedences": [], "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 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.