From 6d37877e49c9844a1eb78acfb5a853c34940ef2c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 5 Oct 2014 16:56:29 -0700 Subject: [PATCH] Tweak debugging output --- include/tree_sitter/parser.h | 4 +++- src/runtime/parser.c | 11 ++++------- src/runtime/stack.h | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 85344443..d040824d 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -96,7 +96,9 @@ struct TSLanguage { DEBUG_LEX((0 < lookahead &&lookahead <= 255 ? "CHAR '%c'" : "CHAR %d"), \ lookahead); -#define START_TOKEN() ts_lexer_start_token(lexer); +#define START_TOKEN() \ + DEBUG_LEX("START TOKEN %lu", lexer->current_position.chars); \ + ts_lexer_start_token(lexer); #define ADVANCE(state_index) \ { \ diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 68af9901..b00365ad 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -37,29 +37,26 @@ static TSLength breakdown_stack(TSParser *parser, TSInputEdit *edit) { if (position.chars < edit->position && !children) break; + DEBUG_PARSE("POP %s", parser->language->symbol_names[node->symbol]); stack->size--; position = ts_length_sub(position, ts_tree_total_size(node)); - DEBUG_PARSE("POP %s %u", parser->language->symbol_names[node->symbol], - ts_stack_top_state(stack)); - for (size_t i = 0; i < child_count && position.chars < edit->position; i++) { TSTree *child = children[i]; TSStateId state = ts_stack_top_state(stack); TSParseAction action = action_for(parser->language, state, child->symbol); TSStateId next_state = action.type == TSParseActionTypeShift ? action.data.to_state : state; + + DEBUG_PARSE("PUT BACK %s", parser->language->symbol_names[child->symbol]); ts_stack_push(stack, next_state, child); position = ts_length_add(position, ts_tree_total_size(child)); - - DEBUG_PARSE("PUT BACK %s %u", - parser->language->symbol_names[child->symbol], next_state); } ts_tree_release(node); } - DEBUG_PARSE("RESUME %lu", position.bytes); + DEBUG_PARSE("RESUME %lu", position.chars); return position; } diff --git a/src/runtime/stack.h b/src/runtime/stack.h index a4941ec8..2e7c9ab9 100644 --- a/src/runtime/stack.h +++ b/src/runtime/stack.h @@ -26,9 +26,9 @@ TSStateId ts_stack_top_state(const TSStack *stack); TSTree *ts_stack_top_node(const TSStack *stack); TSLength ts_stack_right_position(const TSStack *stack); -#define TS_STACK_FROM_TOP(stack, entry) \ - for (TSStackEntry *entry = stack.entries + stack.size - 1; \ - entry >= stack.entries; entry--) +#define TS_STACK_FROM_TOP(stack, entry) \ + for (TSStackEntry *entry = (stack).entries + (stack).size - 1; \ + entry >= (stack).entries; entry--) #ifdef __cplusplus }