diff --git a/grammar.js b/grammar.js index 7283a5e..45cb6cd 100644 --- a/grammar.js +++ b/grammar.js @@ -199,14 +199,15 @@ module.exports = grammar({ _identifier: ($) => seq( - choice(/[\w\d$-]/, $.escape_sequence), + choice(token(prec(PREC.IDENTIFIER, /[\w\d$-]/)), $.escape_sequence), repeat( choice( $.escape_sequence, - token(prec(PREC.IDENTIFIER, /([\w\d'"$(),]+)?( +|-)[\w\d'"$()]+/)) + token(prec(PREC.IDENTIFIER, /[\w\d'"$(),]+/)), + token(prec(PREC.IDENTIFIER, /( +|-)[\w\d'"$()]+/)) ) ), - optional(/[\w\d'"$()]+/), + optional(token(prec(PREC.IDENTIFIER, /[\w\d'"$()]+/))), optional($._dash) ), @@ -388,7 +389,7 @@ module.exports = grammar({ token( prec( PREC.UNQUOTED_STRING, - /[^'"`\\|\n\s;{}\[\]]([^\\\n;{}\[\]]*[^\\\n\s;{}\[\]])?/ + /[^'"`\\|\n\s;{}\[\]][^\\\n;{}\[\]]*[^\\\n\s;{}\[\]]?/ ) ) ) diff --git a/src/grammar.json b/src/grammar.json index e5db853..12d898c 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -866,8 +866,15 @@ "type": "CHOICE", "members": [ { - "type": "PATTERN", - "value": "[\\w\\d$-]" + "type": "TOKEN", + "content": { + "type": "PREC", + "value": 0, + "content": { + "type": "PATTERN", + "value": "[\\w\\d$-]" + } + } }, { "type": "SYMBOL", @@ -891,7 +898,18 @@ "value": 0, "content": { "type": "PATTERN", - "value": "([\\w\\d'\"$(),]+)?( +|-)[\\w\\d'\"$()]+" + "value": "[\\w\\d'\"$(),]+" + } + } + }, + { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": 0, + "content": { + "type": "PATTERN", + "value": "( +|-)[\\w\\d'\"$()]+" } } } @@ -902,8 +920,15 @@ "type": "CHOICE", "members": [ { - "type": "PATTERN", - "value": "[\\w\\d'\"$()]+" + "type": "TOKEN", + "content": { + "type": "PREC", + "value": 0, + "content": { + "type": "PATTERN", + "value": "[\\w\\d'\"$()]+" + } + } }, { "type": "BLANK" @@ -2047,7 +2072,7 @@ "value": -1, "content": { "type": "PATTERN", - "value": "[^'\"`\\\\|\\n\\s;{}\\[\\]]([^\\\\\\n;{}\\[\\]]*[^\\\\\\n\\s;{}\\[\\]])?" + "value": "[^'\"`\\\\|\\n\\s;{}\\[\\]][^\\\\\\n;{}\\[\\]]*[^\\\\\\n\\s;{}\\[\\]]?" } } } diff --git a/src/parser.c b/src/parser.c index 561b158..7978f41 100644 Binary files a/src/parser.c and b/src/parser.c differ diff --git a/test/corpus/shape.txt b/test/corpus/shape.txt index 4f3dcd5..ef18f64 100644 --- a/test/corpus/shape.txt +++ b/test/corpus/shape.txt @@ -1,3 +1,26 @@ +================================================================================ +Declare unquoted shape identifier with escape sequence (issue #21) +================================================================================ +hello\[world\] +\#ello\[world\] +-------------------------------------------------------------------------------- + +(source_file + (shape + (shape_key + (escape_sequence) + (escape_sequence) + ) + ) + (shape + (shape_key + (escape_sequence) + (escape_sequence) + (escape_sequence) + ) + ) +) + ================================================================================ Handle end of file (issue #1) ================================================================================ diff --git a/tree-sitter-d2.wasm b/tree-sitter-d2.wasm index edec16b..526df67 100755 Binary files a/tree-sitter-d2.wasm and b/tree-sitter-d2.wasm differ