Skip to content

Commit 91cca9b

Browse files
committed
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
1 parent 3573bf7 commit 91cca9b

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

corpus/expressions.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,8 @@ object O {
10631063
val y = 2 * x
10641064
y * y
10651065
}
1066+
{ b =>
1067+
if (c) d.e }
10661068
}
10671069

10681070
--------------------------------------------------------------------------------
@@ -1125,7 +1127,17 @@ object O {
11251127
(infix_expression
11261128
(identifier)
11271129
(operator_identifier)
1128-
(identifier))))))))
1130+
(identifier)))))
1131+
(block
1132+
(lambda_expression
1133+
(identifier)
1134+
(indented_block
1135+
(if_expression
1136+
(parenthesized_expression
1137+
(identifier))
1138+
(field_expression
1139+
(identifier)
1140+
(identifier)))))))))
11291141

11301142
================================================================================
11311143
Unit expressions

src/scanner.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
109109
int indentation_size = 0;
110110
LOG("scanner was called at column: %d\n", lexer->get_column(lexer));
111111

112+
while (iswspace(lexer->lookahead)) {
113+
if (lexer->lookahead == '\n') {
114+
newline_count++;
115+
indentation_size = 0;
116+
}
117+
else
118+
indentation_size++;
119+
skip(lexer);
120+
}
121+
112122
// Before advancing the lexer, check if we can double outdent
113123
if (valid_symbols[OUTDENT] &&
114124
(lexer->lookahead == 0 ||
@@ -129,15 +139,6 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
129139
}
130140
stack->last_indentation_size = -1;
131141

132-
while (iswspace(lexer->lookahead)) {
133-
if (lexer->lookahead == '\n') {
134-
newline_count++;
135-
indentation_size = 0;
136-
}
137-
else
138-
indentation_size++;
139-
lexer->advance(lexer, true);
140-
}
141142
printStack(stack, " before");
142143

143144
if (valid_symbols[INDENT] &&
@@ -371,4 +372,4 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
371372
return false;
372373
}
373374

374-
//
375+
//

0 commit comments

Comments
 (0)