Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes inside Markdown #368

Merged
merged 1 commit into from Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/scanner.c
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