tree-sitter/src/compiler
Max Brunsfeld 99d048e016 Simplify error recovery; eliminate recovery states
The previous approach to error recovery relied on special error-recovery
states in the parse table. For each token T, there was an error recovery
state in which the parser looked for *any* token that could follow T.
Unfortunately, sometimes the set of tokens that could follow T contained
conflicts. For example, in JS, the token '}' can be followed by the
open-ended 'template_chars' token, but also by ordinary tokens like
'identifier'. So with the old algorithm, when recovering from an
unexpected '}' token, the lexer had no way to distinguish identifiers
from template_chars.

This commit drops the error recovery states. Instead, when we encounter
an unexpected token T, we recover from the error by finding a previous
state S in the stack in which T would be valid, popping all of the nodes
after S, and wrapping them in an error.

This way, the lexer is always invoked in a normal parse state, in which
it is looking for a non-conflicting set of tokens. Eliminating the error
recovery states also shrinks the lex state machine significantly.

Signed-off-by: Rick Winfrey <rewinfrey@github.com>
2017-09-11 15:22:52 -07:00
..
build_tables Simplify error recovery; eliminate recovery states 2017-09-11 15:22:52 -07:00
generate_code Simplify error recovery; eliminate recovery states 2017-09-11 15:22:52 -07:00
prepare_grammar Recur to sub-rules in a deterministic order in expand_repeats 2017-08-08 17:20:04 -07:00
rules Avoid aggregate initialization syntax in places where C++11 doesn't allow it 2017-08-07 13:07:54 -07:00
util Format make_visitor helper consistently w/ project 2017-03-17 13:37:26 -07:00
compile.cc Move incompatible token map into LexTableBuilder 2017-08-31 15:46:37 -07:00
compile_error.h Implement Rule as a union rather than an abstract base class 2017-03-17 13:29:31 -07:00
grammar.h Add a way to automatically inline rules 2017-07-11 23:13:44 -07:00
lex_table.cc Implement Rule as a union rather than an abstract base class 2017-03-17 13:29:31 -07:00
lex_table.h Merge compatible starting token states before constructing lex table 2017-09-05 13:21:53 -07:00
lexical_grammar.h Implement Rule as a union rather than an abstract base class 2017-03-17 13:29:31 -07:00
parse_grammar.cc Rename RENAME rule to ALIAS, allow it to create anonymous nodes 2017-07-31 16:41:11 -07:00
parse_grammar.h Add a way to automatically inline rules 2017-07-11 23:13:44 -07:00
parse_table.cc Simplify error recovery; eliminate recovery states 2017-09-11 15:22:52 -07:00
parse_table.h Simplify error recovery; eliminate recovery states 2017-09-11 15:22:52 -07:00
precedence_range.cc Include precedence calculation in LexItemSet::transitions 2015-10-30 16:07:29 -07:00
precedence_range.h Include precedence calculation in LexItemSet::transitions 2015-10-30 16:07:29 -07:00
rule.cc Remove use of shared_ptr in choice, repeat, and seq factories 2017-03-17 14:28:13 -07:00
rule.h Remove use of shared_ptr in choice, repeat, and seq factories 2017-03-17 14:28:13 -07:00
syntax_grammar.cc Rename RENAME rule to ALIAS, allow it to create anonymous nodes 2017-07-31 16:41:11 -07:00
syntax_grammar.h Use a constructor rather than aggregate initialization for Production 2017-08-08 10:41:54 -07:00