Skip to content

Commit 866f945

Browse files
authored
Merge pull request #368 from susliko/fix-crash
Fix crashes inside Markdown
2 parents 1b4c2fa + 53c4cb6 commit 866f945

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/scanner.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
117117
int prev = peekStack(stack);
118118
int newline_count = 0;
119119
int indentation_size = 0;
120-
LOG("scanner was called at column: %d\n", lexer->get_column(lexer));
121120

122121
while (iswspace(lexer->lookahead)) {
123122
if (lexer->lookahead == '\n') {
@@ -191,18 +190,16 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
191190
}
192191

193192
// Recover newline_count from the outdent reset
193+
bool is_eof = lexer->eof(lexer);
194194
if (stack->last_newline_count > 0 &&
195-
((lexer->eof(lexer) && stack->last_column == -1)
196-
|| lexer->get_column(lexer) == stack->last_column)) {
195+
((is_eof && stack->last_column == -1) ||
196+
(!is_eof && lexer->get_column(lexer) == stack->last_column))) {
197197
newline_count += stack->last_newline_count;
198198
}
199199
stack->last_newline_count = 0;
200200

201201
printStack(stack, " after");
202202

203-
LOG(" indentation_size: %d, newline_count: %d, column: %d, indent_is_valid: %d, dedent_is_valid: %d\n", indentation_size,
204-
newline_count, lexer->get_column(lexer), valid_symbols[INDENT], valid_symbols[OUTDENT]);
205-
206203
if (valid_symbols[AUTOMATIC_SEMICOLON] && newline_count > 0) {
207204
// AUTOMATIC_SEMICOLON should not be issued in the middle of expressions
208205
// Thus, we exit this branch when encountering comments, else/catch clauses, etc.

0 commit comments

Comments
 (0)