add container key

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-08 01:15:09 +03:00
parent ec5fa08c7c
commit 6835da6d3c
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
11 changed files with 230 additions and 163 deletions

View File

@ -11,7 +11,6 @@ module.exports = grammar({
[$.shape_key],
[$.arrow],
[$._shape_path],
[$._shape_key],
[$._shape_block],
[$._shape_block_definition],
[$._style_attr_block],
@ -47,7 +46,7 @@ module.exports = grammar({
choice(
seq($.dot, $._shape_attribute),
seq(
optional(seq($._colon, optional($.label))),
optional(seq($._colon, optional(seq(spaces, $.label)))),
optional(alias($._shape_block, $.block))
)
)
@ -56,9 +55,23 @@ module.exports = grammar({
),
_shape_path: ($) =>
seq(
spaces,
repeat(seq(alias($.shape_key, $.container_key), spaces, $.dot, spaces)),
$.shape_key
),
shape_key: ($) =>
choice(
$._shape_key,
seq($._shape_key, repeat1(seq($.dot, $._shape_key)))
$.string,
seq(
optional($._dash),
choice(
$._word,
repeat1(seq($._word, choice(repeat1(" "), $._dash), $._word))
),
optional($._dash)
)
),
label: ($) => choice($.string, $._unquoted_string),
@ -157,21 +170,6 @@ module.exports = grammar({
_connection_attr_key: ($) => choice("source-arrowhead", "target-arrowhead"),
_shape_key: ($) => seq(spaces, $.shape_key),
shape_key: ($) =>
choice(
$.string,
seq(
optional($._dash),
choice(
$._word,
repeat1(seq($._word, choice(repeat1(" "), $._dash), $._word))
),
optional($._dash)
)
),
_colon: ($) => seq(spaces, ":"),
_arrow: ($) => seq(spaces, $.arrow),

View File

@ -5,14 +5,16 @@
(invalid (_) @error)
;-------------------------------------------------------------------------------
(container_key) @constant
(shape_key) @variable
(attr_key) @keyword
(attr_key) @property
; Literals
;-------------------------------------------------------------------------------
(string) @string
(label) @string
(container_key (string) @string.special)
(shape_key (string) @string)
(label) @string
(attr_value) @string
; Comments
@ -26,6 +28,7 @@
(arrow) @operator
[
(dot)
":"
";"
] @punctuation.delimiter

View File

@ -141,8 +141,29 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
},
{
"type": "SYMBOL",
"name": "label"
}
]
},
{
"type": "BLANK"
@ -189,34 +210,157 @@
]
},
"_shape_path": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "shape_key"
},
"named": true,
"value": "container_key"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
},
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
}
]
}
},
{
"type": "SYMBOL",
"name": "shape_key"
}
]
},
"shape_key": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_shape_key"
"name": "string"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_shape_key"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "_shape_key"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_word"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_word"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "SYMBOL",
"name": "_dash"
}
]
},
{
"type": "SYMBOL",
"name": "_word"
}
]
}
]
}
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
}
]
}
@ -809,110 +953,6 @@
}
]
},
"_shape_key": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
},
{
"type": "SYMBOL",
"name": "shape_key"
}
]
},
"shape_key": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_word"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_word"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "STRING",
"value": " "
}
},
{
"type": "SYMBOL",
"name": "_dash"
}
]
},
{
"type": "SYMBOL",
"name": "_word"
}
]
}
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
}
]
}
]
},
"_colon": {
"type": "SEQ",
"members": [
@ -1240,9 +1280,6 @@
[
"_shape_path"
],
[
"_shape_key"
],
[
"_shape_block"
],

View File

@ -48,6 +48,10 @@
"type": "connection",
"named": true
},
{
"type": "container_key",
"named": true
},
{
"type": "dot",
"named": true
@ -83,6 +87,10 @@
"type": "attr_value",
"named": true
},
{
"type": "container_key",
"named": true
},
{
"type": "dot",
"named": true
@ -98,6 +106,21 @@
]
}
},
{
"type": "container_key",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "string",
"named": true
}
]
}
},
{
"type": "invalid",
"named": true,
@ -179,6 +202,10 @@
"type": "connection",
"named": true
},
{
"type": "container_key",
"named": true
},
{
"type": "dot",
"named": true

Binary file not shown.

View File

@ -26,7 +26,7 @@ foo: {
(shape_key)
(block
(attr_key) (attr_value)
(shape_key) (dot) (shape_key) (dot) (shape_key)
(container_key) (dot) (container_key) (dot) (shape_key)
(block
(attr_key) (attr_value)
)
@ -44,7 +44,7 @@ foo.bar.baz.shape: oval
(source_file
(shape_key) (dot) (attr_key) (attr_value)
(shape_key) (dot) (shape_key) (dot) (shape_key) (dot) (attr_key) (attr_value)
(container_key) (dot) (container_key) (dot) (shape_key) (dot) (attr_key) (attr_value)
)
================================================================================

View File

@ -149,7 +149,7 @@ bar -> baz: Yes
)
================================================================================
Connection using shape path
Connection of shapes inside a containers
================================================================================
foo.biz.baz -> bar.baz.biz: Label
@ -157,9 +157,9 @@ foo.biz.baz -> bar.baz.biz: Label
(source_file
(connection
(shape_key) (dot) (shape_key) (dot) (shape_key)
(container_key) (dot) (container_key) (dot) (shape_key)
(arrow)
(shape_key) (dot) (shape_key) (dot) (shape_key)
(container_key) (dot) (container_key) (dot) (shape_key)
(label)
)
)

View File

@ -6,7 +6,7 @@ foo.baz
--------------------------------------------------------------------------------
(source_file
(shape_key) (dot) (shape_key)
(container_key) (dot) (shape_key)
)
================================================================================
@ -17,7 +17,7 @@ Use quoted string as a shape key
--------------------------------------------------------------------------------
(source_file
(shape_key (string)) (dot) (shape_key (string))
(container_key (string)) (dot) (shape_key (string))
)
================================================================================

View File

@ -1,5 +1,5 @@
direction: right;
# <- keyword
# <- property
# ^ punctuation.delimiter
# ^ string
# ^ punctuation.delimiter
@ -10,19 +10,19 @@ shape: oval
baaaz.style: {
# <- variable
# ^ keyword
# ^ property
fill: red
# <- keyword
# <- property
# ^ string
}
foo: Label {
shape: oval
# <- keyword
# <- property
# ^ string
style.fill: red;
# <- keyword
# ^ keyword
# <- property
# ^ property
}

View File

@ -1,6 +1,8 @@
foo.'baz'.biz
# <- variable
# ^ string
# <- constant
# ^ punctuation.delimiter
# ^ string.special
# ^ punctuation.delimiter
# ^ variable
'biz': 'Baz'
@ -18,7 +20,7 @@ foo: Foo Bar {
# ^ punctuation.bracket
bar.baz
# <- variable
# <- constant
# ^ variable
}
# <- punctuation.bracket

Binary file not shown.