From ede67db2dc185188bb5f8cc6185fd2ae78cdc753 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Wed, 6 Jul 2022 11:36:42 +0200 Subject: [PATCH 1/2] Don't run external scanner during error recovery --- src/scanner.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/scanner.cc b/src/scanner.cc index 500168b..8c5f40a 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -190,6 +190,16 @@ struct Scanner { } bool scan(TSLexer *lexer, const bool *valid_symbols) { + // During error recovery we don't run the external scanner. This produces + // less accurate results, but avoids a large deal of complexity in this + // scanner. + if (valid_symbols[MULTSTR_START] && valid_symbols[MULTSTR_END] && + valid_symbols[STR_START] && valid_symbols[STR_END] && + valid_symbols[INTERPOLATION_START] && + valid_symbols[INTERPOLATION_END] && valid_symbols[COMMENT]) { + return false; + } + // Skip over all whitespace while (iswspace(lookahead(lexer))) { skip(lexer); @@ -268,7 +278,7 @@ void tree_sitter_nickel_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { Scanner *scanner = static_cast(payload); - uint8_t length_uint8 = (uint8_t) length; + uint8_t length_uint8 = (uint8_t)length; scanner->deserialize(buffer, length_uint8); } From 206c0f8c65bf347654a055c7611839ff4ed883d7 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Wed, 6 Jul 2022 11:38:30 +0200 Subject: [PATCH 2/2] Add test for issue 10 --- corpus/errors.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 corpus/errors.txt diff --git a/corpus/errors.txt b/corpus/errors.txt new file mode 100644 index 0000000..6fb2b4a --- /dev/null +++ b/corpus/errors.txt @@ -0,0 +1,9 @@ +================================================================================ +issue 10 +================================================================================ + +let % + +-------------------------------------------------------------------------------- + +(ERROR)