diff --git a/src/scanner.c b/src/scanner.c index 5fb4f976..cca8f7ab 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -811,7 +811,7 @@ static inline bool scan_literal_content(Scanner *scanner, TSLexer *lexer) { return true; } } else if (lexer->lookahead == '\\') { - if (literal->allows_interpolation) { + if (literal->allows_interpolation && literal->type != REGEX_START) { if (has_content) { lexer->mark_end(lexer); lexer->result_symbol = STRING_CONTENT; diff --git a/test/corpus/literals.txt b/test/corpus/literals.txt index 95efd9f6..cd74532d 100644 --- a/test/corpus/literals.txt +++ b/test/corpus/literals.txt @@ -2080,6 +2080,35 @@ regular expression with interpolation (regex (string_content))) +========================================== +regular expression with character classes +========================================== + +/\d+/ +/\w+/ +/[[:alpha:]]/ +/[[[:alpha:]]\d]+/ +/[[[:alpha:]]\d]+/.match("foo") + +--- + +(program + (regex + (string_content)) + (regex + (string_content)) + (regex + (string_content)) + (regex + (string_content)) + (call + receiver: (regex + (string_content)) + method: (identifier) + arguments: (argument_list + (string + (string_content))))) + ======================================================= percent r regular expression with unbalanced delimiters =======================================================