diff --git a/grammar.js b/grammar.js index de062bf..1b886cf 100644 --- a/grammar.js +++ b/grammar.js @@ -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) diff --git a/src/grammar.json b/src/grammar.json index 78eaf22..3aa6922 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -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'\"$()]+" + } + } } - } + ] } }, { diff --git a/src/node-types.json b/src/node-types.json index b0e05bb..15a9534 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -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 diff --git a/src/parser.c b/src/parser.c index 0552d03..2c3ba0a 100644 Binary files a/src/parser.c and b/src/parser.c differ diff --git a/test/corpus/connection.txt b/test/corpus/connection.txt index e5c6df2..d7bb654 100644 --- a/test/corpus/connection.txt +++ b/test/corpus/connection.txt @@ -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) + ) + ) +) diff --git a/tree-sitter-d2.wasm b/tree-sitter-d2.wasm index 6811bb7..501a657 100755 Binary files a/tree-sitter-d2.wasm and b/tree-sitter-d2.wasm differ