Add structure for container and shapes #1

Merged
pleshevskiy merged 12 commits from rewrite-structure into main 2022-12-09 12:36:32 +03:00
8 changed files with 62 additions and 25 deletions
Showing only changes of commit fb612e11b6 - Show all commits

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,17 +977,24 @@
} }
}, },
"_eol": { "_eol": {
"type": "CHOICE", "type": "TOKEN",
"members": [ "content": {
{ "type": "PREC",
"type": "STRING", "value": -1,
"value": "\n" "content": {
}, "type": "CHOICE",
{ "members": [
"type": "STRING", {
"value": "\u0000" "type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"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.