Rizin
unix-like reverse engineering framework and cli tools
|
#include "runtime/parser.h"
#include <assert.h>
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include "tree_sitter/runtime.h"
#include "runtime/tree.h"
#include "runtime/lexer.h"
#include "runtime/length.h"
#include "runtime/array.h"
#include "runtime/language.h"
#include "runtime/alloc.h"
#include "runtime/reduce_action.h"
#include "runtime/error_costs.h"
Go to the source code of this file.
Classes | |
struct | ErrorRepairSession |
struct | SkipPrecedingTreesSession |
Macros | |
#define | LOG(...) |
#define | LOG_STACK() |
#define | LOG_TREE() |
#define | SYM_NAME(symbol) ts_language_symbol_name(self->language, symbol) |
Typedefs | |
typedef int | CondenseResult |
Functions | |
static void | parser__push (Parser *self, StackVersion version, Tree *tree, TSStateId state) |
static bool | parser__breakdown_top_of_stack (Parser *self, StackVersion version) |
static bool | parser__breakdown_lookahead (Parser *self, Tree **lookahead, TSStateId state, ReusableNode *reusable_node) |
static bool | ts_lex_mode_eq (TSLexMode self, TSLexMode other) |
static bool | parser__can_reuse (Parser *self, TSStateId state, Tree *tree, TableEntry *table_entry) |
static CondenseResult | parser__condense_stack (Parser *self) |
static void | parser__restore_external_scanner (Parser *self, StackVersion version) |
static Tree * | parser__lex (Parser *self, StackVersion version) |
static void | parser__clear_cached_token (Parser *self) |
static Tree * | parser__get_lookahead (Parser *self, StackVersion version, ReusableNode *reusable_node, bool *is_fresh) |
static bool | parser__select_tree (Parser *self, Tree *left, Tree *right) |
static bool | parser__better_version_exists (Parser *self, StackVersion version, ErrorStatus my_error_status) |
static void | parser__shift (Parser *self, StackVersion version, TSStateId state, Tree *lookahead, bool extra) |
static bool | parser__switch_children (Parser *self, Tree *tree, Tree **children, uint32_t count) |
static StackPopResult | parser__reduce (Parser *self, StackVersion version, TSSymbol symbol, unsigned count, bool fragile, bool allow_skipping) |
static const TSParseAction * | parser__reductions_after_sequence (Parser *self, TSStateId start_state, const TreeArray *trees_below, uint32_t tree_count_below, const TreeArray *trees_above, TSSymbol lookahead_symbol, uint32_t *count) |
static StackIterateAction | parser__repair_error_callback (void *payload, TSStateId state, TreeArray *trees, uint32_t tree_count, bool is_done, bool is_pending) |
static bool | parser__repair_error (Parser *self, StackSlice slice, TSSymbol lookahead_symbol, TableEntry entry) |
static void | parser__start (Parser *self, TSInput input, Tree *previous_tree) |
static void | parser__accept (Parser *self, StackVersion version, Tree *lookahead) |
static bool | parser__do_potential_reductions (Parser *self, StackVersion version) |
static StackIterateAction | parser__skip_preceding_trees_callback (void *payload, TSStateId state, TreeArray *trees, uint32_t tree_count, bool is_done, bool is_pending) |
static bool | parser__skip_preceding_trees (Parser *self, StackVersion version, TSSymbol lookahead_symbol) |
static void | parser__handle_error (Parser *self, StackVersion version, TSSymbol lookahead_symbol) |
static void | parser__halt_parse (Parser *self) |
static void | parser__recover (Parser *self, StackVersion version, TSStateId state, Tree *lookahead) |
static void | parser__advance (Parser *self, StackVersion version, ReusableNode *reusable_node) |
bool | parser_init (Parser *self) |
void | parser_set_language (Parser *self, const TSLanguage *language) |
void | parser_destroy (Parser *self) |
Tree * | parser_parse (Parser *self, TSInput input, Tree *old_tree, bool halt_on_error) |
Variables | |
static int | CondenseResultMadeChange = 1 |
static int | CondenseResultAllVersionsHadError = 2 |
#define LOG | ( | ... | ) |
#define LOG_STACK | ( | ) |
#define LOG_TREE | ( | ) |
#define SYM_NAME | ( | symbol | ) | ts_language_symbol_name(self->language, symbol) |
typedef int CondenseResult |
|
static |
Definition at line 815 of file parser.c.
References array_delete, array_splice, assert(), i, k, NULL, parser__select_tree(), root, ts_builtin_sym_end, ts_stack_halt(), ts_stack_pop_all(), ts_stack_push(), and ts_stack_remove_version().
Referenced by parser__advance(), parser__halt_parse(), and parser__recover().
|
static |
Definition at line 1055 of file parser.c.
References test-lz4-speed::action, TableEntry::action_count, TableEntry::actions, array_front, ERROR_STATE, i, LOG, LOG_STACK, parser__accept(), parser__breakdown_lookahead(), parser__breakdown_top_of_stack(), parser__can_reuse(), parser__clear_cached_token(), parser__get_lookahead(), parser__handle_error(), parser__push(), parser__recover(), parser__reduce(), parser__repair_error(), parser__shift(), STACK_VERSION_NONE, SYM_NAME, ts_language_next_state(), ts_language_table_entry(), ts_stack_is_halted(), ts_stack_renumber_version(), TSParseActionTypeAccept, TSParseActionTypeRecover, TSParseActionTypeReduce, TSParseActionTypeShift, and StackSlice::version.
Referenced by parser_parse().
|
static |
Definition at line 437 of file parser.c.
References ErrorStatus::cost, i, LOG, n, ts_stack_halt(), ts_stack_is_halted(), and ts_stack_version_count().
Referenced by parser__handle_error(), parser__recover(), parser__reduce(), and parser__repair_error().
|
static |
|
static |
Definition at line 65 of file parser.c.
References array_delete, array_front, ERROR_STATE, i, LOG, LOG_STACK, parser__push(), SYM_NAME, ts_builtin_sym_error, ts_language_next_state(), ts_stack_pop_pending(), ts_stack_push(), and StackSlice::version.
Referenced by parser__advance(), and parser__get_lookahead().
|
static |
Definition at line 138 of file parser.c.
References TSLexMode::external_lex_state, TableEntry::is_reusable, and ts_lex_mode_eq().
Referenced by parser__advance().
|
static |
Definition at line 332 of file parser.c.
References NULL.
Referenced by parser__advance(), and parser_parse().
|
static |
Definition at line 158 of file parser.c.
References CondenseResultAllVersionsHadError, CondenseResultMadeChange, i, ts_stack_is_halted(), ts_stack_merge(), ts_stack_remove_version(), and ts_stack_version_count().
Referenced by parser_parse().
|
static |
Definition at line 859 of file parser.c.
References test-lz4-speed::action, array_clear, i, parser__reduce(), ts_language_table_entry(), ts_reduce_action_set_add(), ts_stack_remove_version(), ts_stack_renumber_version(), ts_stack_version_count(), TSParseActionTypeRecover, TSParseActionTypeReduce, and TSParseActionTypeShift.
Referenced by parser__handle_error().
|
static |
Definition at line 337 of file parser.c.
References Length::bytes, LOG, parser__breakdown_top_of_stack(), parser__lex(), SYM_NAME, and ts_builtin_sym_error.
Referenced by parser__advance().
|
static |
Definition at line 1005 of file parser.c.
References array_new, length_sub(), length_zero(), LOG, LOG_STACK, parser__accept(), parser__push(), ts_builtin_sym_end, ts_language_symbol_metadata(), and ts_lexer_advance_to_end().
Referenced by parser_parse().
|
static |
Definition at line 961 of file parser.c.
References assert(), ERROR_STATE, LOG, LOG_STACK, NULL, parser__better_version_exists(), parser__do_potential_reductions(), parser__skip_preceding_trees(), ts_stack_halt(), ts_stack_merge(), ts_stack_push(), ts_stack_version_count(), and v.
Referenced by parser__advance().
|
static |
Definition at line 220 of file parser.c.
References Length::bytes, TSPoint::column, ERROR_STATE, Length::extent, TSLexMode::external_lex_state, length_sub(), TSLexMode::lex_state, LOG, memset(), parser__restore_external_scanner(), TSPoint::row, SYM_NAME, ts_builtin_sym_error, ts_language_enabled_external_tokens(), ts_language_symbol_metadata(), ts_lexer_reset(), and ts_lexer_start().
Referenced by parser__get_lookahead().
|
static |
Definition at line 59 of file parser.c.
References ts_stack_push().
Referenced by parser__advance(), parser__breakdown_top_of_stack(), parser__halt_parse(), parser__recover(), parser__reduce(), parser__repair_error(), and parser__skip_preceding_trees().
|
static |
Definition at line 1029 of file parser.c.
References array_new, ERROR_STATE, LOG, parser__accept(), parser__better_version_exists(), parser__push(), parser__shift(), ts_builtin_sym_end, ts_language_symbol_metadata(), ts_stack_copy_version(), and ts_stack_remove_version().
Referenced by parser__advance().
|
static |
Definition at line 504 of file parser.c.
References count, ERROR_STATE, i, parser__better_version_exists(), parser__push(), parser__switch_children(), ts_language_next_state(), ts_language_symbol_metadata(), ts_stack_copy_version(), ts_stack_merge(), ts_stack_pop_count(), ts_stack_push(), ts_stack_remove_version(), ts_stack_version_count(), TS_TREE_STATE_NONE, and StackSlice::version.
Referenced by parser__advance(), and parser__do_potential_reductions().
|
inlinestatic |
Definition at line 598 of file parser.c.
References TSParseAction::child_count, count, ERROR_STATE, i, NULL, start_state(), ts_language_actions(), ts_language_next_state(), TSParseActionTypeReduce, and type.
Referenced by parser__repair_error_callback().
|
static |
Definition at line 715 of file parser.c.
References array_clear, array_delete, array_pop, array_push, array_push_all, ErrorRepairSession::best_repair, ErrorRepairSession::best_repair_next_state, ErrorRepairSession::best_repair_skip_count, ReduceAction::count, error(), ErrorRepairSession::found_repair, i, LOG, ErrorRepairSession::parser, parser__better_version_exists(), parser__push(), parser__repair_error_callback(), SYM_NAME, ReduceAction::symbol, ErrorRepairSession::tree_count_above_error, ts_language_symbol_metadata(), ts_stack_halt(), ts_stack_remove_version(), ts_stack_renumber_version(), TSParseActionTypeReduce, StackSlice::version, and TSSymbolMetadata::visible.
Referenced by parser__advance().
|
static |
Definition at line 651 of file parser.c.
References array_erase, ErrorRepairSession::best_repair, ErrorRepairSession::best_repair_next_state, ErrorRepairSession::best_repair_skip_count, ReduceAction::count, ERROR_STATE, ErrorRepairSession::found_repair, i, ErrorRepairSession::lookahead_symbol, NULL, ErrorRepairSession::parser, parser__reductions_after_sequence(), TSParseAction::symbol, ReduceAction::symbol, ErrorRepairSession::tree_count_above_error, ErrorRepairSession::trees_above_error, ts_language_actions(), and ts_language_next_state().
Referenced by parser__repair_error().
|
static |
|
static |
Definition at line 403 of file parser.c.
Referenced by parser__accept(), and parser__switch_children().
|
static |
Definition at line 461 of file parser.c.
References ts_language_symbol_metadata(), ts_stack_push(), and ts_stack_version_count().
Referenced by parser__advance(), and parser__recover().
|
static |
Definition at line 937 of file parser.c.
References error(), i, parser__push(), parser__skip_preceding_trees_callback(), STACK_VERSION_NONE, and StackSlice::version.
Referenced by parser__handle_error().
|
static |
Definition at line 915 of file parser.c.
References ERROR_STATE, i, SkipPrecedingTreesSession::lookahead_symbol, SkipPrecedingTreesSession::parser, ts_language_actions(), TSParseActionTypeReduce, and type.
Referenced by parser__skip_preceding_trees().
|
static |
Definition at line 797 of file parser.c.
References input(), LOG, NULL, reusable_node_new(), ts_lexer_set_input(), and ts_stack_clear().
Referenced by parser_parse().
|
static |
Definition at line 485 of file parser.c.
References count, and parser__select_tree().
Referenced by parser__reduce().
void parser_destroy | ( | Parser * | self | ) |
Definition at line 1221 of file parser.c.
References array_delete, NULL, parser_set_language(), and ts_stack_delete().
bool parser_init | ( | Parser * | self | ) |
Definition at line 1198 of file parser.c.
References array_init, NULL, ts_lexer_init(), and ts_stack_new().
Definition at line 1233 of file parser.c.
References CondenseResultAllVersionsHadError, CondenseResultMadeChange, input(), LOG, LOG_STACK, LOG_TREE, parser__advance(), parser__clear_cached_token(), parser__condense_stack(), parser__halt_parse(), parser__start(), STACK_VERSION_NONE, ts_stack_clear(), ts_stack_is_halted(), and ts_stack_version_count().
void parser_set_language | ( | Parser * | self, |
const TSLanguage * | language | ||
) |
Definition at line 1209 of file parser.c.
References TSLanguage::create, TSLanguage::external_scanner, and NULL.
Referenced by parser_destroy().
Definition at line 133 of file parser.c.
References TSLexMode::external_lex_state, and TSLexMode::lex_state.
Referenced by parser__can_reuse().
|
static |
Definition at line 156 of file parser.c.
Referenced by parser__condense_stack(), and parser_parse().
|
static |
Definition at line 155 of file parser.c.
Referenced by parser__condense_stack(), and parser_parse().