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

View file

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

View file

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

View file

@ -266,14 +266,6 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "\u0000",
"named": false
},
{
"type": "\n",
"named": false
},
{ {
"type": "\"", "type": "\"",
"named": false "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 # ^ string
foo: Foo Bar { foo: Foo Bar {
# <- variable # <- constant
# ^ string # ^ string
# ^ punctuation.bracket # ^ punctuation.bracket

Binary file not shown.