diff --git a/grammar.js b/grammar.js index 234e513..3a5f5bd 100644 --- a/grammar.js +++ b/grammar.js @@ -286,12 +286,7 @@ module.exports = grammar({ choice( seq( "'", - repeat( - choice( - alias($._unescaped_single_string_fragment, $.string_fragment), - $.escape_sequence - ) - ), + alias($._unescaped_single_string_fragment, $.string_fragment), "'" ), seq( @@ -306,7 +301,7 @@ module.exports = grammar({ ) ), - _unescaped_single_string_fragment: ($) => token.immediate(/[^'\\\n]+/), + _unescaped_single_string_fragment: ($) => token.immediate(/[^'\n]+/), _unescaped_double_string_fragment: ($) => token.immediate(/[^"\\\n]+/), diff --git a/src/grammar.json b/src/grammar.json index 7f29429..df716d9 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1213,25 +1213,13 @@ "value": "'" }, { - "type": "REPEAT", + "type": "ALIAS", "content": { - "type": "CHOICE", - "members": [ - { - "type": "ALIAS", - "content": { - "type": "SYMBOL", - "name": "_unescaped_single_string_fragment" - }, - "named": true, - "value": "string_fragment" - }, - { - "type": "SYMBOL", - "name": "escape_sequence" - } - ] - } + "type": "SYMBOL", + "name": "_unescaped_single_string_fragment" + }, + "named": true, + "value": "string_fragment" }, { "type": "STRING", @@ -1279,7 +1267,7 @@ "type": "IMMEDIATE_TOKEN", "content": { "type": "PATTERN", - "value": "[^'\\\\\\n]+" + "value": "[^'\\n]+" } }, "_unescaped_double_string_fragment": { diff --git a/src/parser.c b/src/parser.c index 5fa5ff9..a33d6fd 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 d7f751e..0011321 100644 --- a/test/corpus/shape.txt +++ b/test/corpus/shape.txt @@ -57,6 +57,25 @@ Use quoted string as a shape key (shape (shape_key (string (string_fragment)))) ) +================================================================================ +Use escape sequence in quoted string as a shape key +================================================================================ +'\# hello \# world' + +"\# hello \# world" + +-------------------------------------------------------------------------------- + +(source_file + (shape (shape_key (string (string_fragment)))) + (shape (shape_key (string + (escape_sequence) + (string_fragment) + (escape_sequence) + (string_fragment) + ))) +) + ================================================================================ Define multiple shapes using semicolons ================================================================================ @@ -159,9 +178,9 @@ foo: |go ) ================================================================================ -Text block with quotes (d2-vim style) +Text block with quotes (custom escape characters) ================================================================================ -foo: |`go +foo: |$$$go awsSession := From(c.Request.Context()) @@ -171,7 +190,7 @@ foo: |`go ctx, cancelFn := context.WithTimeout(c.Request.Context(), AWS_TIMEOUT) defer cancelFn() -`| +$$$| -------------------------------------------------------------------------------- @@ -190,7 +209,7 @@ Online text block ================================================================================ foo: | helo world | -bar: |%%md ## hello world %%| +bar: |##md ## hello world ##| -------------------------------------------------------------------------------- diff --git a/tree-sitter-d2.wasm b/tree-sitter-d2.wasm index 96a1442..df6db89 100755 Binary files a/tree-sitter-d2.wasm and b/tree-sitter-d2.wasm differ