clang-format

This commit is contained in:
Max Brunsfeld 2015-12-29 21:17:31 -08:00
parent 939476c947
commit 4ad1a666be
5 changed files with 62 additions and 43 deletions

View file

@ -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

View file

@ -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();"); });

View file

@ -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];
}

View file

@ -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

View file

@ -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,