From 59cc65c2e3d29599bf4ab81582f3cf13dc872855 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 29 Jun 2014 00:20:16 -0700 Subject: [PATCH] Rename parse action types --- include/tree_sitter/parser/state_machine.h | 18 +++++++++--------- include/tree_sitter/runtime.h | 3 --- src/runtime/state_machine.c | 20 +++++++++----------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/tree_sitter/parser/state_machine.h b/include/tree_sitter/parser/state_machine.h index 2d64c44a..d0a4d765 100644 --- a/include/tree_sitter/parser/state_machine.h +++ b/include/tree_sitter/parser/state_machine.h @@ -9,11 +9,11 @@ extern "C" { #include "tree_sitter/parser/lexer.h" typedef enum { - ts_parse_action_type_error, - ts_parse_action_type_shift, - ts_parse_action_type_shift_extra, - ts_parse_action_type_reduce, - ts_parse_action_type_accept, + TSParseActionTypeError, + TSParseActionTypeShift, + TSParseActionTypeShiftExtra, + TSParseActionTypeReduce, + TSParseActionTypeAccept, } TSParseActionType; typedef struct { @@ -28,16 +28,16 @@ typedef struct { } TSParseAction; #define SHIFT(to_state_value) \ -{ .type = ts_parse_action_type_shift, .data = { .to_state = to_state_value } } +{ .type = TSParseActionTypeShift, .data = { .to_state = to_state_value } } #define SHIFT_EXTRA() \ -{ .type = ts_parse_action_type_shift_extra } +{ .type = TSParseActionTypeShiftExtra } #define REDUCE(symbol_val, child_count_val) \ -{ .type = ts_parse_action_type_reduce, .data = { .symbol = symbol_val, .child_count = child_count_val } } +{ .type = TSParseActionTypeReduce, .data = { .symbol = symbol_val, .child_count = child_count_val } } #define ACCEPT_INPUT() \ -{ .type = ts_parse_action_type_accept } +{ .type = TSParseActionTypeAccept } typedef struct { TSLexer lexer; diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index ad59b1aa..e81b5108 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -48,9 +48,6 @@ typedef struct { void *data; } TSParser; -const TSTree * ts_parser_parse(TSParser *, TSInput, TSInputEdit *edit); -void ts_parser_free(TSParser *); - typedef struct TSDocument TSDocument; TSDocument * ts_document_make(); void ts_document_free(TSDocument *doc); diff --git a/src/runtime/state_machine.c b/src/runtime/state_machine.c index 642fd6d2..219d7e8b 100644 --- a/src/runtime/state_machine.c +++ b/src/runtime/state_machine.c @@ -62,13 +62,13 @@ TSSymbol * expected_symbols(TSStateMachine *machine, size_t *count) { *count = 0; const TSParseAction *actions = actions_for_state(machine, ts_stack_top_state(&machine->stack)); for (size_t i = 0; i < machine->config.symbol_count; i++) - if (actions[i].type != ts_parse_action_type_error) + if (actions[i].type != TSParseActionTypeError) ++(*count); size_t n = 0; TSSymbol *result = malloc(*count * sizeof(*result)); for (TSSymbol i = 0; i < machine->config.symbol_count; i++) - if (actions[i].type != ts_parse_action_type_error) + if (actions[i].type != TSParseActionTypeError) result[n++] = i; return result; @@ -105,9 +105,9 @@ int handle_error(TSStateMachine *machine) { size_t i = machine->stack.size - 1 - j; TSStateId stack_state = machine->stack.entries[i].state; TSParseAction action_on_error = actions_for_state(machine, stack_state)[ts_builtin_sym_error]; - if (action_on_error.type == ts_parse_action_type_shift) { + if (action_on_error.type == TSParseActionTypeShift) { TSStateId state_after_error = action_on_error.data.to_state; - if (actions_for_state(machine, state_after_error)[ts_tree_symbol(machine->lookahead)].type != ts_parse_action_type_error) { + if (actions_for_state(machine, state_after_error)[ts_tree_symbol(machine->lookahead)].type != TSParseActionTypeError) { ts_stack_shrink(&machine->stack, i + 1); ts_stack_push(&machine->stack, state_after_error, error); return 1; @@ -199,8 +199,6 @@ void ts_state_machine_initialize(TSStateMachine *machine, TSInput input, TSInput ts_lexer_advance(&machine->lexer); } -/* #define TS_DEBUG_PARSE */ - #ifdef TS_DEBUG_PARSE #include #define DEBUG_PARSE(...) fprintf(stderr, "\n" __VA_ARGS__) @@ -212,22 +210,22 @@ TSTree * ts_state_machine_parse(TSStateMachine *machine, const char **symbol_nam TSParseAction action = get_next_action(machine); DEBUG_PARSE("LOOKAHEAD %s", symbol_names[ts_tree_symbol(machine->lookahead)]); switch (action.type) { - case ts_parse_action_type_shift: + case TSParseActionTypeShift: DEBUG_PARSE("SHIFT %d", action.data.to_state); shift(machine, action.data.to_state, 0); return NULL; - case ts_parse_action_type_shift_extra: + case TSParseActionTypeShiftExtra: DEBUG_PARSE("SHIFT EXTRA"); shift(machine, ts_stack_top_state(&machine->stack), 1); return NULL; - case ts_parse_action_type_reduce: + case TSParseActionTypeReduce: DEBUG_PARSE("REDUCE %s %d", symbol_names[action.data.symbol], action.data.child_count); reduce(machine, action.data.symbol, action.data.child_count); return NULL; - case ts_parse_action_type_accept: + case TSParseActionTypeAccept: DEBUG_PARSE("ACCEPT"); return get_tree_root(machine); - case ts_parse_action_type_error: + case TSParseActionTypeError: DEBUG_PARSE("ERROR"); if (handle_error(machine)) return NULL;