Make tree struct private
This commit is contained in:
parent
50a90e456b
commit
95188d84b6
6 changed files with 68 additions and 42 deletions
|
|
@ -287,15 +287,15 @@ static size_t ts_lr_parser_breakdown_stack(ts_lr_parser *parser, ts_input_edit *
|
|||
if (position <= edit->position && !children) break;
|
||||
|
||||
stack->size--;
|
||||
position -= (node->offset + node->size);
|
||||
position -= ts_tree_total_size(node);
|
||||
|
||||
for (size_t i = 0; i < child_count && position < edit->position; i++) {
|
||||
ts_tree *child = children[i];
|
||||
state_id state = ts_stack_top_state(stack);
|
||||
state_id next_state = ts_parse_actions[state][child->symbol].data.to_state;
|
||||
state_id next_state = ts_parse_actions[state][ts_tree_symbol(child)].data.to_state;
|
||||
ts_stack_push(stack, next_state, child);
|
||||
ts_tree_retain(child);
|
||||
position += child->offset + child->size;
|
||||
position += ts_tree_total_size(child);
|
||||
}
|
||||
|
||||
ts_tree_release(node);
|
||||
|
|
@ -356,7 +356,7 @@ static int ts_lr_parser_handle_error(ts_lr_parser *parser) {
|
|||
if (ts_lexer_position(&parser->lexer) == position)
|
||||
ts_lexer_advance(&parser->lexer);
|
||||
|
||||
if (parser->lookahead->symbol == ts_builtin_sym_end) {
|
||||
if (ts_tree_symbol(parser->lookahead) == ts_builtin_sym_end) {
|
||||
parser->stack.entries[0].node = error;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ static int ts_lr_parser_handle_error(ts_lr_parser *parser) {
|
|||
ts_parse_action action_on_error = ts_parse_actions[stack_state][ts_builtin_sym_error];
|
||||
if (action_on_error.type == ts_parse_action_type_shift) {
|
||||
state_id state_after_error = action_on_error.data.to_state;
|
||||
if (ts_parse_actions[state_after_error][parser->lookahead->symbol].type != ts_parse_action_type_error) {
|
||||
if (ts_parse_actions[state_after_error][ts_tree_symbol(parser->lookahead)].type != ts_parse_action_type_error) {
|
||||
ts_stack_shrink(&parser->stack, i + 1);
|
||||
ts_stack_push(&parser->stack, state_after_error, error);
|
||||
return 1;
|
||||
|
|
@ -388,7 +388,7 @@ static const ts_tree * ts_parse(void *data, ts_input input, ts_input_edit *edit)
|
|||
state_id state = ts_stack_top_state(&parser->stack);
|
||||
if (!parser->lookahead)
|
||||
parser->lookahead = ts_lex(&parser->lexer, ts_lex_states[state]);
|
||||
ts_parse_action action = ts_parse_actions[state][parser->lookahead->symbol];
|
||||
ts_parse_action action = ts_parse_actions[state][ts_tree_symbol(parser->lookahead)];
|
||||
switch (action.type) {
|
||||
case ts_parse_action_type_shift:
|
||||
ts_lr_parser_shift(parser, action.data.to_state);
|
||||
|
|
|
|||
|
|
@ -11,25 +11,7 @@ typedef int ts_symbol;
|
|||
static const ts_symbol ts_builtin_sym_error = -1;
|
||||
static const ts_symbol ts_builtin_sym_end = -2;
|
||||
|
||||
typedef struct ts_tree {
|
||||
ts_symbol symbol;
|
||||
size_t ref_count;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
short int is_hidden;
|
||||
union {
|
||||
struct {
|
||||
size_t count;
|
||||
struct ts_tree **contents;
|
||||
} children;
|
||||
struct {
|
||||
char lookahead_char;
|
||||
size_t expected_input_count;
|
||||
const ts_symbol *expected_inputs;
|
||||
} error;
|
||||
} data;
|
||||
} ts_tree;
|
||||
|
||||
typedef struct ts_tree ts_tree;
|
||||
ts_tree * ts_tree_make_leaf(ts_symbol symbol, size_t size, size_t offset);
|
||||
ts_tree * ts_tree_make_node(ts_symbol symbol, size_t child_count, ts_tree **children, size_t size, size_t offset);
|
||||
ts_tree * ts_tree_make_error(char lookahead_char, size_t expected_input_count, const ts_symbol *expected_inputs, size_t size, size_t offset);
|
||||
|
|
@ -39,6 +21,11 @@ int ts_tree_equals(const ts_tree *tree1, const ts_tree *tree2);
|
|||
char * ts_tree_string(const ts_tree *tree, const char **names);
|
||||
char * ts_tree_error_string(const ts_tree *tree, const char **names);
|
||||
ts_tree ** ts_tree_children(const ts_tree *tree, size_t *count);
|
||||
size_t ts_tree_size(const ts_tree *tree);
|
||||
size_t ts_tree_offset(const ts_tree *tree);
|
||||
size_t ts_tree_total_size(const ts_tree *tree);
|
||||
ts_symbol ts_tree_symbol(const ts_tree *tree);
|
||||
void ts_tree_hide(ts_tree *tree, int hide);
|
||||
|
||||
typedef struct {
|
||||
void *data;
|
||||
|
|
@ -64,7 +51,6 @@ const ts_tree * ts_parser_parse(ts_parser *, ts_input, ts_input_edit *edit);
|
|||
void ts_parser_free(ts_parser *);
|
||||
|
||||
typedef struct ts_document ts_document;
|
||||
|
||||
ts_document * ts_document_make();
|
||||
void ts_document_free(ts_document *doc);
|
||||
void ts_document_set_parser(ts_document *doc, ts_parser parser);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue