fix available characters in the identifier
This commit is contained in:
parent
3c622036f6
commit
84103fee37
7 changed files with 87 additions and 73 deletions
17
grammar.js
17
grammar.js
|
@ -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: ($) =>
|
||||
|
|
107
src/grammar.json
107
src/grammar.json
|
@ -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": "`"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
src/parser.c
BIN
src/parser.c
Binary file not shown.
|
@ -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))
|
||||
)
|
||||
|
||||
================================================================================
|
||||
|
|
|
@ -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.
Loading…
Reference in a new issue