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

View file

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

View file

@ -141,8 +141,29 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "label" "members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
},
{
"type": "SYMBOL",
"name": "label"
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -189,34 +210,157 @@
] ]
}, },
"_shape_path": { "_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", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_shape_key" "name": "string"
}, },
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "_shape_key" "members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
}, },
{ {
"type": "REPEAT1", "type": "CHOICE",
"content": { "members": [
"type": "SEQ", {
"members": [ "type": "SYMBOL",
{ "name": "_word"
"type": "SYMBOL", },
"name": "dot" {
}, "type": "REPEAT1",
{ "content": {
"type": "SYMBOL", "type": "SEQ",
"name": "_shape_key" "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": { "_colon": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -1240,9 +1280,6 @@
[ [
"_shape_path" "_shape_path"
], ],
[
"_shape_key"
],
[ [
"_shape_block" "_shape_block"
], ],

View file

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

Binary file not shown.

View file

@ -26,7 +26,7 @@ foo: {
(shape_key) (shape_key)
(block (block
(attr_key) (attr_value) (attr_key) (attr_value)
(shape_key) (dot) (shape_key) (dot) (shape_key) (container_key) (dot) (container_key) (dot) (shape_key)
(block (block
(attr_key) (attr_value) (attr_key) (attr_value)
) )
@ -44,7 +44,7 @@ foo.bar.baz.shape: oval
(source_file (source_file
(shape_key) (dot) (attr_key) (attr_value) (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 foo.biz.baz -> bar.baz.biz: Label
@ -157,9 +157,9 @@ foo.biz.baz -> bar.baz.biz: Label
(source_file (source_file
(connection (connection
(shape_key) (dot) (shape_key) (dot) (shape_key) (container_key) (dot) (container_key) (dot) (shape_key)
(arrow) (arrow)
(shape_key) (dot) (shape_key) (dot) (shape_key) (container_key) (dot) (container_key) (dot) (shape_key)
(label) (label)
) )
) )

View file

@ -6,7 +6,7 @@ foo.baz
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (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 (source_file
(shape_key (string)) (dot) (shape_key (string)) (container_key (string)) (dot) (shape_key (string))
) )
================================================================================ ================================================================================

View file

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

View file

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

Binary file not shown.