fix available characters in the identifier

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-09 23:44:43 +03:00
parent 3c622036f6
commit 84103fee37
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
7 changed files with 87 additions and 73 deletions

View file

@ -22,8 +22,6 @@ module.exports = grammar({
$.line_comment,
],
word: ($) => $._identifier,
conflicts: ($) => [[$._connection_path, $.container]],
rules: {
@ -116,14 +114,17 @@ module.exports = grammar({
)
),
shape_key: ($) => choice($.string, seq($._identifier, optional($._dash))),
shape_key: ($) => choice($.string, $._identifier),
_identifier: ($) =>
token(
prec(
PREC.IDENTIFIER,
/\-?([\w\d]+([\w\d`'"]+)?|([\w\d]+([\w\d `'"]+)?( +|\-)[\w\d]+([\w\d `'"]+)?)+)/
)
seq(
optional("-"),
/[\w\d$]/,
repeat(
token(prec(PREC.IDENTIFIER, /([\w\d'"$(),]+)?( +|-)[\w\d'"$()]+/))
),
optional(/[\w\d'"$()]+/),
optional($._dash)
),
text_block: ($) =>

View file

@ -1,6 +1,5 @@
{
"name": "d2",
"word": "_identifier",
"rules": {
"source_file": {
"type": "REPEAT",
@ -474,38 +473,69 @@
"name": "string"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
}
]
"type": "SYMBOL",
"name": "_identifier"
}
]
},
"_identifier": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "BLANK"
}
]
},
{
"type": "PATTERN",
"value": "\\-?([\\w\\d]+([\\w\\d`'\"]+)?|([\\w\\d]+([\\w\\d `'\"]+)?( +|\\-)[\\w\\d]+([\\w\\d `'\"]+)?)+)"
"value": "[\\w\\d$]"
},
{
"type": "REPEAT",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"content": {
"type": "PATTERN",
"value": "([\\w\\d'\"$(),]+)?( +|-)[\\w\\d'\"$()]+"
}
}
}
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[\\w\\d'\"$()]+"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
}
}
]
},
"text_block": {
"type": "CHOICE",
@ -1249,29 +1279,6 @@
"value": "\""
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "`"
},
{
"type": "REPEAT",
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[^`\\n]+"
}
}
},
{
"type": "STRING",
"value": "`"
}
]
}
]
},

View file

@ -322,6 +322,10 @@
"type": "'",
"named": false
},
{
"type": "-",
"named": false
},
{
"type": "3d",
"named": false
@ -334,10 +338,6 @@
"type": ";",
"named": false
},
{
"type": "`",
"named": false
},
{
"type": "`|",
"named": false

Binary file not shown.

View file

@ -103,20 +103,24 @@ Complex identifier connection
================================================================================
Foo Bar -- Biz Baz
-Bar-Foo- <- -Baz-Biz-
imAShape -- im_a_shape
im_a_shape -- im$AShape
im a shape -- i'm $a shape
i'm a shape -- a-sh$ape
a-shape -- im a sh$ape
foo' 'bar -- baz
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key)
(arrow)
(shape_key)
)
(connection
(shape_key)
(arrow)
(shape_key)
)
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
(connection (shape_key) (arrow) (shape_key))
)
================================================================================

View file

@ -27,10 +27,11 @@ Complex shape key
Foo bar
-Biz-baz-
imAShape
im_a_shape
im_a$_shape
im a shape
i'm a shape
a-shape
changeTeam(member, props, ctx)
--------------------------------------------------------------------------------
@ -42,6 +43,7 @@ a-shape
(shape (shape_key))
(shape (shape_key))
(shape (shape_key))
(shape (shape_key))
)
================================================================================

Binary file not shown.