Issue OUTDENT with extra spaces before brackets

Problem
-------
```scala
{ x =>
  if (a) b.c }
```
is not parsed because OUTDENT token is not emitted in a presense of
space characters before the closing bracket

Solution
-------
Reorder space-handling and outdent-ing logic in external scanner
text_sliders
susliko 2023-06-10 23:51:37 +07:00
parent 3573bf75fe
commit 16974b4535
3 changed files with 25 additions and 12 deletions

@ -1063,6 +1063,8 @@ object O {
val y = 2 * x
y * y
}
{ b =>
if (c) d.e }
}
--------------------------------------------------------------------------------
@ -1125,7 +1127,17 @@ object O {
(infix_expression
(identifier)
(operator_identifier)
(identifier))))))))
(identifier)))))
(block
(lambda_expression
(identifier)
(indented_block
(if_expression
(parenthesized_expression
(identifier))
(field_expression
(identifier)
(identifier)))))))))
================================================================================
Unit expressions

@ -2,7 +2,7 @@
# This is an integration test to generally check the quality of parsing.
SCALA_SCALA_LIBRARY_EXPECTED=99
SCALA_SCALA_LIBRARY_EXPECTED=100
SCALA_SCALA_COMPILER_EXPECTED=95
DOTTY_COMPILER_EXPECTED=83
SYNTAX_COMPLEXITY_CEILING=1300

21
src/scanner.c vendored

@ -109,6 +109,16 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
int indentation_size = 0;
LOG("scanner was called at column: %d\n", lexer->get_column(lexer));
while (iswspace(lexer->lookahead)) {
if (lexer->lookahead == '\n') {
newline_count++;
indentation_size = 0;
}
else
indentation_size++;
skip(lexer);
}
// Before advancing the lexer, check if we can double outdent
if (valid_symbols[OUTDENT] &&
(lexer->lookahead == 0 ||
@ -129,15 +139,6 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
}
stack->last_indentation_size = -1;
while (iswspace(lexer->lookahead)) {
if (lexer->lookahead == '\n') {
newline_count++;
indentation_size = 0;
}
else
indentation_size++;
lexer->advance(lexer, true);
}
printStack(stack, " before");
if (valid_symbols[INDENT] &&
@ -371,4 +372,4 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
return false;
}
//
//