Compare commits

...

2 Commits

Author SHA1 Message Date
Dmitriy Pleshevskiy e7507ddd98
grammar: add support of referencing connection
Closes #18
2023-06-22 02:12:18 +03:00
Dmitriy Pleshevskiy 731be00903
grammar: some cleanup 2023-06-21 23:52:40 +03:00
6 changed files with 389 additions and 112 deletions

View File

@ -69,6 +69,7 @@ module.exports = grammar({
[$.class_list],
[$.attr_value_list],
[$._text_block_attrs],
[$._identifier],
],
rules: {
@ -93,14 +94,24 @@ module.exports = grammar({
connection: ($) =>
seq(
$._connection_path,
repeat1(seq($.arrow, $._connection_path)),
seq(
optional(seq($._colon, optional($.label))),
optional(seq(alias($._connection_block, $.block)))
)
choice(
$._full_connection_path,
alias($._referencing_full_connection_path, $.referencing)
),
optional(seq($._colon, optional($.label))),
optional(seq(alias($._connection_block, $.block)))
),
_referencing_full_connection_path: ($) =>
seq("(", $._full_connection_path, $._referencing_end, optional($.index)),
_referencing_end: ($) => token(prec(PREC.IDENTIFIER + 1, ")")),
index: ($) => seq("[", $.integer, "]"),
_full_connection_path: ($) =>
seq($._connection_path, repeat1(seq($.arrow, $._connection_path))),
_connection_path: ($) =>
seq(
repeat(
@ -203,11 +214,17 @@ module.exports = grammar({
repeat(
choice(
$.escape_sequence,
token(prec(PREC.IDENTIFIER, /[\w\d'"$(),]+/)),
token(prec(PREC.IDENTIFIER, /( +|-)[\w\d'"$()]+/))
token(prec(PREC.IDENTIFIER, /[\w\d'"$(,]+/)),
token(prec(PREC.IDENTIFIER, /( +|-)[\w\d'"$(]+/)),
token(prec(PREC.IDENTIFIER, ")"))
)
),
optional(
choice(
token(prec(PREC.IDENTIFIER, /[\w\d'"$(]+/)),
token(prec(PREC.IDENTIFIER + 1, ")"))
)
),
optional(token(prec(PREC.IDENTIFIER, /[\w\d'"$()]+/))),
optional($._dash)
),
@ -370,13 +387,13 @@ module.exports = grammar({
attr_value_list: mkList(($) => $.attr_value),
attr_value: ($) =>
seq(choice($.boolean, $.integer, $.float, $.string, $._unquoted_string)),
choice($.boolean, $.integer, $.float, $.string, $._unquoted_string),
// --------------------------------------------
_dash: ($) => token.immediate("-"),
_colon: ($) => seq(":"),
_colon: ($) => token(":"),
arrow: ($) => token(prec(PREC.ARROW, choice(/-+>/, /--+/, /<-+/, /<-+>/))),

View File

@ -66,6 +66,137 @@
]
},
"connection": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_full_connection_path"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_referencing_full_connection_path"
},
"named": true,
"value": "referencing"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_connection_block"
},
"named": true,
"value": "block"
}
]
},
{
"type": "BLANK"
}
]
}
]
},
"_referencing_full_connection_path": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_full_connection_path"
},
{
"type": "SYMBOL",
"name": "_referencing_end"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "index"
},
{
"type": "BLANK"
}
]
}
]
},
"_referencing_end": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": ")"
}
}
},
"index": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "STRING",
"value": "]"
}
]
},
"_full_connection_path": {
"type": "SEQ",
"members": [
{
@ -87,62 +218,6 @@
}
]
}
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_connection_block"
},
"named": true,
"value": "block"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
]
},
@ -898,7 +973,7 @@
"value": 0,
"content": {
"type": "PATTERN",
"value": "[\\w\\d'\"$(),]+"
"value": "[\\w\\d'\"$(,]+"
}
}
},
@ -909,7 +984,18 @@
"value": 0,
"content": {
"type": "PATTERN",
"value": "( +|-)[\\w\\d'\"$()]+"
"value": "( +|-)[\\w\\d'\"$(]+"
}
}
},
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"content": {
"type": "STRING",
"value": ")"
}
}
}
@ -920,15 +1006,31 @@
"type": "CHOICE",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"content": {
"type": "PATTERN",
"value": "[\\w\\d'\"$()]+"
"type": "CHOICE",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"content": {
"type": "PATTERN",
"value": "[\\w\\d'\"$(]+"
}
}
},
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": ")"
}
}
}
}
]
},
{
"type": "BLANK"
@ -1976,32 +2078,27 @@
]
},
"attr_value": {
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "_unquoted_string"
}
]
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "_unquoted_string"
}
]
},
@ -2013,13 +2110,11 @@
}
},
"_colon": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
}
]
"type": "TOKEN",
"content": {
"type": "STRING",
"value": ":"
}
},
"arrow": {
"type": "TOKEN",
@ -2299,6 +2394,9 @@
],
[
"_text_block_attrs"
],
[
"_identifier"
]
],
"precedences": [],

View File

@ -261,7 +261,7 @@
"fields": {},
"children": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "arrow",
@ -283,6 +283,10 @@
"type": "label",
"named": true
},
{
"type": "referencing",
"named": true
},
{
"type": "shape_key",
"named": true
@ -348,6 +352,21 @@
]
}
},
{
"type": "index",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "integer",
"named": true
}
]
}
},
{
"type": "label",
"named": true,
@ -367,6 +386,37 @@
]
}
},
{
"type": "referencing",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "arrow",
"named": true
},
{
"type": "container_key",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "index",
"named": true
},
{
"type": "shape_key",
"named": true
}
]
}
},
{
"type": "reserved",
"named": true,
@ -512,11 +562,15 @@
"named": false
},
{
"type": "3d",
"type": "(",
"named": false
},
{
"type": ":",
"type": ")",
"named": false
},
{
"type": "3d",
"named": false
},
{

Binary file not shown.

View File

@ -248,7 +248,7 @@ Connection with espaced key fragments
================================================================================
Connection with espaced key fragments
Diclare a connection with espaced key fragments
================================================================================
\#hello\[\] -- \[world\]
@ -268,3 +268,111 @@ Connection with espaced key fragments
)
)
)
================================================================================
Declare a referencing connection
================================================================================
(x() -> y())
(x() -> y())[0]
--------------------------------------------------------------------------------
(source_file
(connection
(referencing
(shape_key)
(arrow)
(shape_key)
)
)
(connection
(referencing
(shape_key)
(arrow)
(shape_key)
(index (integer))
)
)
)
================================================================================
Declare a referencing connection with label
================================================================================
(x -> y): label
(x -> y)[0]: label
--------------------------------------------------------------------------------
(source_file
(connection
(referencing
(shape_key)
(arrow)
(shape_key)
)
(label)
)
(connection
(referencing
(shape_key)
(arrow)
(shape_key)
(index (integer))
)
(label)
)
)
================================================================================
Declare a referencing connection with block
================================================================================
(x() -> y()): {
style.stroke: \#ff0000
}
(x -> y)[0]: {
style.stroke: \#ff0000
}
--------------------------------------------------------------------------------
(source_file
(connection
(referencing
(shape_key)
(arrow)
(shape_key)
)
(block
(attribute
(keyword_style)
(dot)
(attribute
(attr_key)
(attr_value
(escape_sequence)
)
)
)
)
)
(connection
(referencing
(shape_key)
(arrow)
(shape_key)
(index (integer))
)
(block
(attribute
(keyword_style)
(dot)
(attribute
(attr_key)
(attr_value
(escape_sequence)
)
)
)
)
)
)

Binary file not shown.