diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 1330759e..5ce5cd2e 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -149,47 +149,60 @@ enum { CAN_HIDE_SPLIT = 2, }; -#define ERROR() {{.type = TSParseActionTypeError}} +#define ERROR() \ + { \ + { .type = TSParseActionTypeError } \ + } -#define SHIFT(to_state_value, flags) \ - {{ \ - .type = TSParseActionTypeShift, \ - .can_hide_split = (flags & CAN_HIDE_SPLIT) != 0, \ - .data = {.to_state = to_state_value } \ - }} +#define SHIFT(to_state_value, flags) \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .can_hide_split = (flags & CAN_HIDE_SPLIT) != 0, \ + .data = {.to_state = to_state_value } \ + } \ + } -#define SHIFT_EXTRA() \ - {{ .type = TSParseActionTypeShift, .extra = true }} +#define SHIFT_EXTRA() \ + { \ + { .type = TSParseActionTypeShift, .extra = true } \ + } -#define REDUCE_EXTRA(symbol_val) \ - {{ \ - .type = TSParseActionTypeReduce, .extra = true, \ - .data = {.symbol = symbol_val, .child_count = 1 } \ - }} +#define REDUCE_EXTRA(symbol_val) \ + { \ + { \ + .type = TSParseActionTypeReduce, .extra = true, \ + .data = {.symbol = symbol_val, .child_count = 1 } \ + } \ + } -#define REDUCE(symbol_val, child_count_val, flags) \ - {{ \ - .type = TSParseActionTypeReduce, .fragile = (flags & FRAGILE) != 0, \ - .can_hide_split = (flags & CAN_HIDE_SPLIT) != 0, \ - .data = {.symbol = symbol_val, .child_count = child_count_val } \ - }} +#define REDUCE(symbol_val, child_count_val, flags) \ + { \ + { \ + .type = TSParseActionTypeReduce, .fragile = (flags & FRAGILE) != 0, \ + .can_hide_split = (flags & CAN_HIDE_SPLIT) != 0, \ + .data = {.symbol = symbol_val, .child_count = child_count_val } \ + } \ + } -#define ACCEPT_INPUT() \ - {{ .type = TSParseActionTypeAccept }} +#define ACCEPT_INPUT() \ + { \ + { .type = TSParseActionTypeAccept } \ + } -#define EXPORT_LANGUAGE(language_name) \ - static TSLanguage language = { \ - .symbol_count = SYMBOL_COUNT, \ - .symbol_metadata = ts_symbol_metadata, \ - .parse_table = (const unsigned short *)ts_parse_table, \ - .parse_actions = ts_parse_actions, \ - .lex_states = ts_lex_states, \ - .symbol_names = ts_symbol_names, \ - .lex_fn = ts_lex, \ - }; \ - \ - const TSLanguage *language_name() { \ - return &language; \ +#define EXPORT_LANGUAGE(language_name) \ + static TSLanguage language = { \ + .symbol_count = SYMBOL_COUNT, \ + .symbol_metadata = ts_symbol_metadata, \ + .parse_table = (const unsigned short *)ts_parse_table, \ + .parse_actions = ts_parse_actions, \ + .lex_states = ts_lex_states, \ + .symbol_names = ts_symbol_names, \ + .lex_fn = ts_lex, \ + }; \ + \ + const TSLanguage *language_name() { \ + return &language; \ } #ifdef __cplusplus diff --git a/src/compiler/generate_code/c_code.cc b/src/compiler/generate_code/c_code.cc index 1c5d2399..664ee40c 100644 --- a/src/compiler/generate_code/c_code.cc +++ b/src/compiler/generate_code/c_code.cc @@ -193,8 +193,7 @@ class CCodeGenerator { line("START_LEXER();"); _switch("lex_state", [&]() { for (size_t i = 1; i < lex_table.states.size(); i++) - _case(to_string(i), - [&]() { add_lex_state(lex_table.states[i]); }); + _case(to_string(i), [&]() { add_lex_state(lex_table.states[i]); }); _case("ts_lex_state_error", [&]() { add_lex_state(lex_table.states[0]); }); _default([&]() { line("LEX_ERROR();"); }); diff --git a/src/runtime/language.c b/src/runtime/language.c index ad2064f3..0ad4c08a 100644 --- a/src/runtime/language.c +++ b/src/runtime/language.c @@ -1,7 +1,10 @@ #include "tree_sitter/parser.h" -const TSParseAction *ts_language_actions(const TSLanguage *language, TSStateId state, TSSymbol sym, size_t *count) { - unsigned short action_index = (language->parse_table + (state * language->symbol_count))[sym]; +const TSParseAction *ts_language_actions(const TSLanguage *language, + TSStateId state, TSSymbol sym, + size_t *count) { + unsigned short action_index = + (language->parse_table + (state * language->symbol_count))[sym]; *count = language->parse_actions[action_index].count; const TSParseActionEntry *entry = language->parse_actions + action_index + 1; return (const TSParseAction *)entry; @@ -10,7 +13,8 @@ const TSParseAction *ts_language_actions(const TSLanguage *language, TSStateId s TSParseAction ts_language_last_action(const TSLanguage *language, TSStateId state, TSSymbol sym) { size_t count; - const TSParseAction *actions = ts_language_actions(language, state, sym, &count); + const TSParseAction *actions = + ts_language_actions(language, state, sym, &count); return actions[count - 1]; } diff --git a/src/runtime/language.h b/src/runtime/language.h index 2b2890bb..33f3835c 100644 --- a/src/runtime/language.h +++ b/src/runtime/language.h @@ -7,7 +7,8 @@ extern "C" { #include "tree_sitter/parser.h" -const TSParseAction *ts_language_actions(const TSLanguage *, TSStateId, TSSymbol, size_t *); +const TSParseAction *ts_language_actions(const TSLanguage *, TSStateId, + TSSymbol, size_t *); TSParseAction ts_language_last_action(const TSLanguage *, TSStateId, TSSymbol); #ifdef __cplusplus diff --git a/src/runtime/parser.c b/src/runtime/parser.c index b4614dfe..d2971a1a 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -142,7 +142,8 @@ static bool ts_parser__can_reuse(TSParser *self, int head, TSTree *subtree) { return false; } - const TSParseAction action = ts_language_last_action(self->language, state, subtree->symbol); + const TSParseAction action = + ts_language_last_action(self->language, state, subtree->symbol); if (action.type == TSParseActionTypeError || action.can_hide_split) return false; @@ -543,7 +544,8 @@ static bool ts_parser__consume_lookahead(TSParser *self, int head, for (;;) { TSStateId state = ts_stack_top_state(self->stack, head); size_t action_count; - const TSParseAction *actions = ts_language_actions(self->language, state, lookahead->symbol, &action_count); + const TSParseAction *actions = ts_language_actions( + self->language, state, lookahead->symbol, &action_count); /* * If there are multiple actions for the current state and lookahead symbol,