Skip to content

Commit

Permalink
fix: detect in error recovery and exit scan
Browse files Browse the repository at this point in the history
  • Loading branch information
polarmutex committed Jul 2, 2023
1 parent ff7f3b5 commit f3c05c6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using std::iswspace;
using std::vector;

enum TokenType {
HL_STARS,
SECTION,
SECTIONEND,
END_OF_FILE,
};
Expand Down Expand Up @@ -75,8 +75,16 @@ struct Scanner {
lexer->advance(lexer, true);
}

static bool in_error_recovery(const bool *valid_symbols) {
return (valid_symbols[SECTION] && valid_symbols[SECTIONEND]
&& valid_symbols[END_OF_FILE]);
}

bool scan(TSLexer *lexer, const bool *valid_symbols) {

if (in_error_recovery(valid_symbols))
return false;

// - Section ends
int16_t indent_length = 0;
lexer->mark_end(lexer);
Expand Down Expand Up @@ -116,9 +124,9 @@ struct Scanner {
org_section_stack.pop_back();
lexer->result_symbol = SECTIONEND;
return true;
} else if (valid_symbols[HL_STARS] && iswspace(lexer->lookahead)) {
} else if (valid_symbols[SECTION] && iswspace(lexer->lookahead)) {
org_section_stack.push_back(stars);
lexer->result_symbol = HL_STARS;
lexer->result_symbol = SECTION;
return true;
}
return false;
Expand Down

0 comments on commit f3c05c6

Please sign in to comment.