Skip to content

Commit

Permalink
Merge pull request #368 from susliko/fix-crash
Browse files Browse the repository at this point in the history
Fix crashes inside Markdown
  • Loading branch information
eed3si9n authored Dec 21, 2023
2 parents 1b4c2fa + 53c4cb6 commit 866f945
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
int prev = peekStack(stack);
int newline_count = 0;
int indentation_size = 0;
LOG("scanner was called at column: %d\n", lexer->get_column(lexer));

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

// Recover newline_count from the outdent reset
bool is_eof = lexer->eof(lexer);
if (stack->last_newline_count > 0 &&
((lexer->eof(lexer) && stack->last_column == -1)
|| lexer->get_column(lexer) == stack->last_column)) {
((is_eof && stack->last_column == -1) ||
(!is_eof && lexer->get_column(lexer) == stack->last_column))) {
newline_count += stack->last_newline_count;
}
stack->last_newline_count = 0;

printStack(stack, " after");

LOG(" indentation_size: %d, newline_count: %d, column: %d, indent_is_valid: %d, dedent_is_valid: %d\n", indentation_size,
newline_count, lexer->get_column(lexer), valid_symbols[INDENT], valid_symbols[OUTDENT]);

if (valid_symbols[AUTOMATIC_SEMICOLON] && newline_count > 0) {
// AUTOMATIC_SEMICOLON should not be issued in the middle of expressions
// Thus, we exit this branch when encountering comments, else/catch clauses, etc.
Expand Down

0 comments on commit 866f945

Please sign in to comment.