add shape block

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-06 12:32:50 +03:00
parent 41e2ce2e57
commit e7421caac0
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 235 additions and 11 deletions

View file

@ -8,8 +8,11 @@ module.exports = grammar({
word: ($) => $._word, word: ($) => $._word,
conflicts: ($) => [ conflicts: ($) => [
[$._identifier],
[$.identifier], [$.identifier],
[$.arrow], [$.arrow],
[$._shape_block],
[$._shape_block_definition],
[$._style_attr_block], [$._style_attr_block],
[$._inner_style_attribute], [$._inner_style_attribute],
], ],
@ -18,7 +21,7 @@ module.exports = grammar({
source_file: ($) => repeat($._definition), source_file: ($) => repeat($._definition),
_definition: ($) => _definition: ($) =>
choice($._end, $._root_attribute, $.connection, $.shape), choice(seq(spaces, $._eof), $._root_attribute, $.connection, $.shape),
connection: ($) => connection: ($) =>
seq( seq(
@ -35,7 +38,14 @@ module.exports = grammar({
$._identifier, $._identifier,
repeat(seq($.dot, $._identifier)), repeat(seq($.dot, $._identifier)),
optional( optional(
choice(seq($.dot, $._shape_attribute), seq($._colon, $.label)) choice(
seq($.dot, $._shape_attribute),
seq(
$._colon,
optional($.label),
optional(alias($._shape_block, $.block))
)
)
), ),
$._end $._end
), ),
@ -49,6 +59,22 @@ module.exports = grammar({
_root_attr_key: ($) => "direction", _root_attr_key: ($) => "direction",
_shape_block: ($) =>
seq(
spaces,
"{",
spaces,
repeat(
choice(seq(spaces, $._eof), seq($._shape_block_definition, $._end))
),
optional(seq($._shape_block_definition, optional($._end))),
spaces,
"}"
),
_shape_block_definition: ($) =>
choice($.connection, $.shape, $._shape_attribute),
_shape_attribute: ($) => _shape_attribute: ($) =>
choice( choice(
seq(alias($._shape_attr_key, $.attr_key), $._colon, $.attr_value), seq(alias($._shape_attr_key, $.attr_key), $._colon, $.attr_value),

View file

@ -12,9 +12,21 @@
"_definition": { "_definition": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_end" "name": "_eof"
}
]
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -147,9 +159,34 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "_colon" "name": "_colon"
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "label" "name": "label"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_shape_block"
},
"named": true,
"value": "block"
},
{
"type": "BLANK"
}
]
} }
] ]
} }
@ -234,6 +271,123 @@
"type": "STRING", "type": "STRING",
"value": "direction" "value": "direction"
}, },
"_shape_block": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_shape_block_definition"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_shape_block_definition"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_shape_block_definition": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "connection"
},
{
"type": "SYMBOL",
"name": "shape"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
"_shape_attribute": { "_shape_attribute": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -884,12 +1038,21 @@
}, },
"extras": [], "extras": [],
"conflicts": [ "conflicts": [
[
"_identifier"
],
[ [
"identifier" "identifier"
], ],
[ [
"arrow" "arrow"
], ],
[
"_shape_block"
],
[
"_shape_block_definition"
],
[ [
"_style_attr_block" "_style_attr_block"
], ],

View file

@ -39,6 +39,22 @@
{ {
"type": "attr_value", "type": "attr_value",
"named": true "named": true
},
{
"type": "block",
"named": true
},
{
"type": "connection",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "shape",
"named": true
} }
] ]
} }

Binary file not shown.

View file

@ -38,6 +38,7 @@ Block style attributes
================================================================================ ================================================================================
foo.style: { foo.style: {
opacity: 5 opacity: 5
fill: red; fill: red;
} }
@ -77,8 +78,3 @@ foo.style: { opacity: 5 }
) )
) )

View file

@ -83,3 +83,26 @@ bar : Foo Bar; baz
(shape (identifier)) (shape (identifier))
) )
================================================================================
Shape block
================================================================================
foo: {
bar: {
baz: {
biz
}
}
}
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (block
(shape (identifier) (block
(shape (identifier) (block
(shape (identifier))
))
))
))
)