Remove expected symbols from error nodes
This commit is contained in:
parent
25a254a732
commit
16d5cf1d04
3 changed files with 25 additions and 56 deletions
|
|
@ -55,18 +55,8 @@ static size_t breakdown_stack(TSParser *parser, TSInputEdit *edit) {
|
|||
}
|
||||
|
||||
static TSTree *build_error_node(TSParser *parser) {
|
||||
TSStateId state = ts_stack_top_state(&parser->stack);
|
||||
unsigned char lookahead = ts_lexer_lookahead_char(&parser->lexer);
|
||||
TSSymbol *expected_symbols =
|
||||
malloc(parser->language->symbol_count * sizeof(TSSymbol *));
|
||||
|
||||
size_t count = 0;
|
||||
const TSParseAction *actions = actions_for_state(parser->language, state);
|
||||
for (TSSymbol i = 0; i < parser->language->symbol_count; i++)
|
||||
if (actions[i].type != TSParseActionTypeError)
|
||||
expected_symbols[count++] = i;
|
||||
|
||||
return ts_tree_make_error(lookahead, count, expected_symbols, 0, 0);
|
||||
return ts_tree_make_error(0, 0, lookahead);
|
||||
}
|
||||
|
||||
static void shift(TSParser *parser, TSStateId parse_state) {
|
||||
|
|
|
|||
|
|
@ -3,32 +3,22 @@
|
|||
#include "tree_sitter/parser.h"
|
||||
#include "runtime/tree.h"
|
||||
|
||||
static TSTree *ts_tree_make(TSSymbol symbol, size_t size, size_t padding,
|
||||
int is_hidden) {
|
||||
TSTree *ts_tree_make_leaf(TSSymbol s, size_t size, size_t padding, int hidden) {
|
||||
TSTree *result = malloc(sizeof(TSTree));
|
||||
*result = (TSTree) { .ref_count = 1,
|
||||
.symbol = symbol,
|
||||
.symbol = s,
|
||||
.size = size,
|
||||
.child_count = 0,
|
||||
.children = NULL,
|
||||
.lookahead_char = 0,
|
||||
.padding = padding,
|
||||
.options = is_hidden ? TSTreeOptionsHidden : 0, };
|
||||
.options = hidden ? TSTreeOptionsHidden : 0, };
|
||||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_error(char lookahead_char, size_t expected_input_count,
|
||||
const TSSymbol *expected_inputs, size_t size,
|
||||
size_t padding) {
|
||||
TSTree *result = ts_tree_make(ts_builtin_sym_error, size, padding, 0);
|
||||
TSTree *ts_tree_make_error(size_t size, size_t padding, char lookahead_char) {
|
||||
TSTree *result = ts_tree_make_leaf(ts_builtin_sym_error, size, padding, 0);
|
||||
result->lookahead_char = lookahead_char;
|
||||
result->expected_input_count = expected_input_count;
|
||||
result->expected_inputs = expected_inputs;
|
||||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol symbol, size_t size, size_t padding,
|
||||
int is_hidden) {
|
||||
TSTree *result = ts_tree_make(symbol, size, padding, is_hidden);
|
||||
result->child_count = 0;
|
||||
result->children = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -74,14 +64,13 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
|||
malloc(sizeof(TSTree) + (visible_child_count * sizeof(TSTreeChild)));
|
||||
*result = (TSTree) { .ref_count = 1,
|
||||
.symbol = symbol,
|
||||
.children = children,
|
||||
.child_count = child_count,
|
||||
.visible_child_count = visible_child_count,
|
||||
.size = size,
|
||||
.padding = padding,
|
||||
.options = options };
|
||||
|
||||
result->children = children;
|
||||
result->child_count = child_count;
|
||||
result->visible_child_count = visible_child_count;
|
||||
|
||||
/*
|
||||
* Associate a relative offset with each of the visible child nodes, so that
|
||||
* their positions can be queried without using the hidden child nodes.
|
||||
|
|
@ -134,15 +123,15 @@ size_t ts_tree_total_size(const TSTree *tree) {
|
|||
int ts_tree_equals(const TSTree *node1, const TSTree *node2) {
|
||||
if (node1->symbol != node2->symbol)
|
||||
return 0;
|
||||
if (node1->symbol == ts_builtin_sym_error) {
|
||||
// check error equality
|
||||
} else {
|
||||
if (node1->child_count != node2->child_count)
|
||||
if (node1->lookahead_char != node2->lookahead_char)
|
||||
return 0;
|
||||
if (node1->child_count != node2->child_count)
|
||||
return 0;
|
||||
if (node1->visible_child_count != node2->visible_child_count)
|
||||
return 0;
|
||||
for (size_t i = 0; i < node1->child_count; i++)
|
||||
if (!ts_tree_equals(node1->children[i], node2->children[i]))
|
||||
return 0;
|
||||
for (size_t i = 0; i < node1->child_count; i++)
|
||||
if (!ts_tree_equals(node1->children[i], node2->children[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,18 +19,10 @@ struct TSTree {
|
|||
size_t ref_count;
|
||||
size_t padding;
|
||||
size_t size;
|
||||
union {
|
||||
struct {
|
||||
size_t child_count;
|
||||
struct TSTree **children;
|
||||
size_t visible_child_count;
|
||||
};
|
||||
struct {
|
||||
size_t expected_input_count;
|
||||
const TSSymbol *expected_inputs;
|
||||
char lookahead_char;
|
||||
};
|
||||
};
|
||||
char lookahead_char;
|
||||
size_t child_count;
|
||||
size_t visible_child_count;
|
||||
struct TSTree **children;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -78,9 +70,7 @@ TSTree *ts_tree_make_leaf(TSSymbol symbol, size_t size, size_t padding,
|
|||
int is_hidden);
|
||||
TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
||||
TSTree **children, int is_hidden);
|
||||
TSTree *ts_tree_make_error(char lookahead_char, size_t expected_input_count,
|
||||
const TSSymbol *expected_inputs, size_t size,
|
||||
size_t padding);
|
||||
TSTree *ts_tree_make_error(size_t size, size_t padding, char lookahead_char);
|
||||
void ts_tree_retain(TSTree *tree);
|
||||
void ts_tree_release(TSTree *tree);
|
||||
int ts_tree_equals(const TSTree *tree1, const TSTree *tree2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue