Skip to content

Commit fc5bcbc

Browse files
committed
Give a name to unescaped string fragments so as to obtain a node in the CST.
(workaround for tree-sitter/tree-sitter#1156)
1 parent ae9bc67 commit fc5bcbc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

grammar.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,21 +866,32 @@ module.exports = grammar({
866866
seq(
867867
'"',
868868
repeat(choice(
869-
token.immediate(prec(1, /[^"\\]+/)),
869+
alias($.unescaped_double_string_fragment, $.string_fragment),
870870
$.escape_sequence
871871
)),
872872
'"'
873873
),
874874
seq(
875875
"'",
876876
repeat(choice(
877-
token.immediate(prec(1, /[^'\\]+/)),
877+
alias($.unescaped_single_string_fragment, $.string_fragment),
878878
$.escape_sequence
879879
)),
880880
"'"
881881
)
882882
),
883883

884+
// Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
885+
// We give names to the token() constructs containing a regexp
886+
// so as to obtain a node in the CST.
887+
//
888+
unescaped_double_string_fragment: $ =>
889+
token.immediate(prec(1, /[^"\\]+/)),
890+
891+
// same here
892+
unescaped_single_string_fragment: $ =>
893+
token.immediate(prec(1, /[^'\\]+/)),
894+
884895
escape_sequence: $ => token.immediate(seq(
885896
'\\',
886897
choice(

0 commit comments

Comments
 (0)