add container and shape blocks to conflicts

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-09 12:01:25 +03:00
parent a95e6251f0
commit fb612e11b6
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
8 changed files with 62 additions and 25 deletions

View File

@ -1,9 +1,12 @@
const PREC = {
COMMENT: -2,
EOL: -1,
UNQUOTED_STRING: 0,
CONTAINER: 2,
CONNECTION: 2,
SHAPE: 3,
CONTAINER_BLOCK: 4,
SHAPE_BLOCK: 4,
IDENTIFIER: 0,
ARROW: 0,
ATTRIBUTE: 0,
@ -20,7 +23,10 @@ module.exports = grammar({
word: ($) => $._identifier,
conflicts: ($) => [[$._connection_path, $.container]],
conflicts: ($) => [
[$._connection_path, $.container],
[$._container_block_definition, $._shape_block_definition],
],
rules: {
source_file: ($) => repeat($._root_definition),
@ -83,7 +89,7 @@ module.exports = grammar({
_container_block_definition: ($) =>
prec(
PREC.CONTAINER,
PREC.CONTAINER_BLOCK,
choice($._eol, seq(choice($.shape, $.container, $.connection), $._end))
),
@ -114,7 +120,7 @@ module.exports = grammar({
_shape_block: ($) =>
prec(PREC.SHAPE, seq("{", repeat($._shape_block_definition), "}")),
_shape_block_definition: ($) => prec(PREC.SHAPE, choice($._eol)),
_shape_block_definition: ($) => prec(PREC.SHAPE_BLOCK, choice($._eol)),
// attributes
@ -233,7 +239,7 @@ module.exports = grammar({
line_comment: ($) => token(prec(PREC.COMMENT, seq("#", /.*/))),
_eol: ($) => choice("\n", "\0"),
_eol: ($) => token(prec(PREC.EOL, choice("\n", "\0"))),
_end: ($) => seq(choice(";", $._eol)),
},
});

View File

@ -3,6 +3,7 @@
(container_key) @constant
(shape_key) @variable
(attr_key) @property
(reserved) @error
; Literals
;-------------------------------------------------------------------------------

View File

@ -265,7 +265,7 @@
},
"_container_block_definition": {
"type": "PREC",
"value": 2,
"value": 4,
"content": {
"type": "CHOICE",
"members": [
@ -469,7 +469,7 @@
},
"_shape_block_definition": {
"type": "PREC",
"value": 3,
"value": 4,
"content": {
"type": "CHOICE",
"members": [
@ -977,17 +977,24 @@
}
},
"_eol": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
}
]
}
]
}
},
"_end": {
"type": "SEQ",
@ -1022,6 +1029,10 @@
[
"_connection_path",
"container"
],
[
"_container_block_definition",
"_shape_block_definition"
]
],
"precedences": [],

View File

@ -266,14 +266,6 @@
"named": true,
"fields": {}
},
{
"type": "\u0000",
"named": false
},
{
"type": "\n",
"named": false
},
{
"type": "\"",
"named": false

Binary file not shown.

View File

@ -196,4 +196,31 @@ Foo biz bar: Biz biz Bar {
)
)
================================================================================
Declare shapes sparsely in a container
================================================================================
Foo: Baz {
biz
baz
bar
}
--------------------------------------------------------------------------------
(source_file
(container
(container_key)
(label)
(block
(shape (shape_key))
(shape (shape_key))
(shape (shape_key))
)
)
)

View File

@ -15,7 +15,7 @@ foo: Foo Bar
# ^ string
foo: Foo Bar {
# <- variable
# <- constant
# ^ string
# ^ punctuation.bracket

Binary file not shown.