grammar: add support of underscore keyword...

...to ref the parent container

Closes #5
This commit is contained in:
Dmitriy Pleshevskiy 2023-06-16 07:42:49 +03:00
parent e67c50d7cb
commit 9828b023cd
Signed by: pleshevskiy
GPG key ID: 79C4487B44403985
10 changed files with 84 additions and 29 deletions

View file

@ -1,12 +1,7 @@
# Actors # Actors
hans: Hans Niemann hans: Hans Niemann
defendants: |md defendants: {
# Defendants
hello world
| {
shape: text
mc: Magnus Carlsen mc: Magnus Carlsen
playmagnus: Play Magnus Group playmagnus: Play Magnus Group
chesscom: Chess.com chesscom: Chess.com

View file

@ -188,7 +188,7 @@ module.exports = grammar({
) )
), ),
shape_key: ($) => choice($.string, $._identifier), shape_key: ($) => choice($.keyword_underscore, $.string, $._identifier),
_identifier: ($) => _identifier: ($) =>
seq( seq(
@ -348,6 +348,7 @@ module.exports = grammar({
_connection_arrowhead_attr_key: ($) => _connection_arrowhead_attr_key: ($) =>
choice("source-arrowhead", "target-arrowhead"), choice("source-arrowhead", "target-arrowhead"),
keyword_underscore: (_) => "_",
keyword_classes: (_) => "classes", keyword_classes: (_) => "classes",
keyword_class: (_) => "class", keyword_class: (_) => "class",
keyword_style: (_) => "style", keyword_style: (_) => "style",

View file

@ -4,12 +4,15 @@
(shape_key) @variable (shape_key) @variable
(attr_key) @property (attr_key) @property
(reserved) @error (reserved) @error
(class_name) @constant
[ [
(keyword_style) (keyword_style)
(keyword_classes) (keyword_classes)
(keyword_class) (keyword_class)
] @keyword ] @keyword
(class_name) @constant
(keyword_underscore) @keyword.return
; Literals ; Literals
;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------

View file

@ -853,6 +853,10 @@
"shape_key": { "shape_key": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "keyword_underscore"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "string" "name": "string"
@ -1818,6 +1822,10 @@
} }
] ]
}, },
"keyword_underscore": {
"type": "STRING",
"value": "_"
},
"keyword_classes": { "keyword_classes": {
"type": "STRING", "type": "STRING",
"value": "classes" "value": "classes"
@ -2080,20 +2088,7 @@
"type": "PATTERN", "type": "PATTERN",
"value": "[0-9]+\\.[0-9]+" "value": "[0-9]+\\.[0-9]+"
}, },
"comment": { "line_comment": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_line_comment"
},
{
"type": "SYMBOL",
"name": "_block_comment"
}
]
},
"_line_comment": {
"type": "TOKEN", "type": "TOKEN",
"content": { "content": {
"type": "PREC", "type": "PREC",
@ -2150,7 +2145,11 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "comment" "name": "line_comment"
},
{
"type": "SYMBOL",
"name": "block_comment"
} }
], ],
"conflicts": [ "conflicts": [
@ -2196,7 +2195,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_block_comment" "name": "block_comment"
} }
], ],
"inline": [], "inline": [],

View file

@ -186,6 +186,10 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "keyword_underscore",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -232,11 +236,6 @@
] ]
} }
}, },
{
"type": "comment",
"named": true,
"fields": {}
},
{ {
"type": "connection", "type": "connection",
"named": true, "named": true,
@ -319,6 +318,10 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "keyword_underscore",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -397,6 +400,10 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "keyword_underscore",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -513,6 +520,10 @@
"type": "arrow", "type": "arrow",
"named": true "named": true
}, },
{
"type": "block_comment",
"named": true
},
{ {
"type": "bold", "type": "bold",
"named": false "named": false
@ -613,6 +624,10 @@
"type": "keyword_style", "type": "keyword_style",
"named": true "named": true
}, },
{
"type": "keyword_underscore",
"named": true
},
{ {
"type": "label", "type": "label",
"named": false "named": false
@ -621,6 +636,10 @@
"type": "language", "type": "language",
"named": true "named": true
}, },
{
"type": "line_comment",
"named": true
},
{ {
"type": "link", "type": "link",
"named": false "named": false

Binary file not shown.

View file

@ -267,3 +267,25 @@ primty: Primitive types {
) )
) )
) )
================================================================================
Declare a container with a references to the parent container
================================================================================
container: {
_.foo: baz
}
--------------------------------------------------------------------------------
(source_file
(container
(container_key)
(block
(container
(container_key (keyword_underscore))
(dot)
(shape (shape_key) (label))
)
)
)
)

View file

@ -278,3 +278,13 @@ bar
(block_comment) (block_comment)
(shape (shape_key)) (shape (shape_key))
) )
================================================================================
Declare a shape with a parent container reference
================================================================================
_
--------------------------------------------------------------------------------
(source_file
(shape (shape_key (keyword_underscore)))
)

View file

@ -33,6 +33,12 @@ foo: Foo Bar {
bar.baz bar.baz
# <- string.special # <- string.special
# ^ variable # ^ variable
_.foo.style.fill: "#8800aa"
# <- keyword.return
# ^ variable
# ^ keyword
# ^ property
} }
# <- punctuation.bracket # <- punctuation.bracket

Binary file not shown.