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

View file

@ -1,6 +1,5 @@
{ {
"name": "d2", "name": "d2",
"word": "_identifier",
"rules": { "rules": {
"source_file": { "source_file": {
"type": "REPEAT", "type": "REPEAT",
@ -474,38 +473,69 @@
"name": "string" "name": "string"
}, },
{ {
"type": "SEQ", "type": "SYMBOL",
"members": [ "name": "_identifier"
{
"type": "SYMBOL",
"name": "_identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_dash"
},
{
"type": "BLANK"
}
]
}
]
} }
] ]
}, },
"_identifier": { "_identifier": {
"type": "TOKEN", "type": "SEQ",
"content": { "members": [
"type": "PREC", {
"value": 0, "type": "CHOICE",
"content": { "members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "BLANK"
}
]
},
{
"type": "PATTERN", "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": { "text_block": {
"type": "CHOICE", "type": "CHOICE",
@ -1249,29 +1279,6 @@
"value": "\"" "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": "'", "type": "'",
"named": false "named": false
}, },
{
"type": "-",
"named": false
},
{ {
"type": "3d", "type": "3d",
"named": false "named": false
@ -334,10 +338,6 @@
"type": ";", "type": ";",
"named": false "named": false
}, },
{
"type": "`",
"named": false
},
{ {
"type": "`|", "type": "`|",
"named": false "named": false

Binary file not shown.

View file

@ -103,20 +103,24 @@ Complex identifier connection
================================================================================ ================================================================================
Foo Bar -- Biz Baz Foo Bar -- Biz Baz
-Bar-Foo- <- -Baz-Biz- -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 (source_file
(connection (connection (shape_key) (arrow) (shape_key))
(shape_key) (connection (shape_key) (arrow) (shape_key))
(arrow) (connection (shape_key) (arrow) (shape_key))
(shape_key) (connection (shape_key) (arrow) (shape_key))
) (connection (shape_key) (arrow) (shape_key))
(connection (connection (shape_key) (arrow) (shape_key))
(shape_key) (connection (shape_key) (arrow) (shape_key))
(arrow) (connection (shape_key) (arrow) (shape_key))
(shape_key)
)
) )
================================================================================ ================================================================================

View file

@ -27,10 +27,11 @@ Complex shape key
Foo bar Foo bar
-Biz-baz- -Biz-baz-
imAShape imAShape
im_a_shape im_a$_shape
im a shape im a shape
i'm a shape i'm a shape
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))
(shape (shape_key)) (shape (shape_key))
(shape (shape_key))
) )
================================================================================ ================================================================================

Binary file not shown.