grammar: add escape sequence for unquoted string

Closes #8
This commit is contained in:
Dmitriy Pleshevskiy 2023-01-05 16:28:22 +03:00
parent 4fdf38aebe
commit b9fa5785b4
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 55 additions and 24 deletions

View file

@ -130,10 +130,12 @@ module.exports = grammar({
_identifier: ($) =>
seq(
optional("-"),
/[\w\d$]/,
choice(/[\w\d$-]/, $.escape_sequence),
repeat(
token(prec(PREC.IDENTIFIER, /([\w\d'"$(),]+)?( +|-)[\w\d'"$()]+/))
choice(
$.escape_sequence,
token(prec(PREC.IDENTIFIER, /([\w\d'"$(),]+)?( +|-)[\w\d'"$()]+/))
)
),
optional(/[\w\d'"$()]+/),
optional($._dash)

View file

@ -539,30 +539,36 @@
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
"type": "PATTERN",
"value": "[\\w\\d$-]"
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "escape_sequence"
}
]
},
{
"type": "PATTERN",
"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": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"content": {
"type": "PATTERN",
"value": "([\\w\\d'\"$(),]+)?( +|-)[\\w\\d'\"$()]+"
}
}
}
}
]
}
},
{

View file

@ -183,9 +183,13 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
},
{
"type": "string",
"named": true
@ -249,9 +253,13 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
},
{
"type": "string",
"named": true
@ -336,10 +344,6 @@
"type": "'",
"named": false
},
{
"type": "-",
"named": false
},
{
"type": "3d",
"named": false

Binary file not shown.

View file

@ -226,3 +226,22 @@ foo.baz: {
)
)
)
================================================================================
Connection with espaced key fragments
================================================================================
\#(hello)- -- b\#-world
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key
(escape_sequence)
)
(arrow)
(shape_key
(escape_sequence)
)
)
)

Binary file not shown.