Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
bool found_non_alnumdollarunderdash;
bool last_was_escape;
bool in_single_quote;
bool in_double_quote;
uint32_t paren_depth;
uint32_t bracket_depth;
uint32_t brace_depth;
Expand All @@ -716,7 +717,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {

lexer->mark_end(lexer);

State state = {false, false, false, false, false, 0, 0, 0};
State state = {false, false, false, false, false, false, 0, 0, 0};
while (!state.done) {
if (state.in_single_quote) {
if (lexer->lookahead == '\'') {
Expand Down Expand Up @@ -773,14 +774,23 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
state.advanced_once = true;
state.last_was_escape = false;
continue;
case '"':
// Enter or exit a double-quoted string.
if (!state.last_was_escape) {
state.in_double_quote = !state.in_double_quote;
}
advance(lexer);
state.advanced_once = true;
state.last_was_escape = false;
continue;
default:
state.last_was_escape = false;
break;
}

if (!state.done) {
if (valid_symbols[REGEX]) {
bool was_space = !state.in_single_quote && iswspace(lexer->lookahead);
bool was_space = !state.in_single_quote && !state.in_double_quote && iswspace(lexer->lookahead);
advance(lexer);
state.advanced_once = true;
if (!was_space || state.paren_depth > 0) {
Expand All @@ -800,7 +810,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
lexer->mark_end(lexer);
}
} else {
bool was_space = !state.in_single_quote && iswspace(lexer->lookahead);
bool was_space = !state.in_single_quote && !state.in_double_quote && iswspace(lexer->lookahead);
advance(lexer);
state.advanced_once = true;
if (!was_space) {
Expand Down Expand Up @@ -830,7 +840,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
return true;
}
} else {
bool was_space = !state.in_single_quote && iswspace(lexer->lookahead);
bool was_space = !state.in_single_quote && !state.in_double_quote && iswspace(lexer->lookahead);
if (was_space && state.paren_depth == 0) {
lexer->mark_end(lexer);
lexer->result_symbol = REGEX_NO_SPACE;
Expand Down
192 changes: 124 additions & 68 deletions src/tree_sitter/array.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,36 @@ Test commands with regexes
(variable_name))
(regex))))

================================================================================
Test commands with glob patterns containing quoted spaces
================================================================================

[[ "${tmp}" = *"A B"* ]]
[[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]
[[ "${tmp}" = *'single quoted with space'* ]]

---

(program
(test_command
(binary_expression
(string
(expansion
(variable_name)))
(regex)))
(test_command
(binary_expression
(string
(expansion
(variable_name)))
(regex)))
(test_command
(binary_expression
(string
(expansion
(variable_name)))
(regex))))

================================================================================
Test command paren statefulness with a case glob
================================================================================
Expand Down