From c0a3f8d39c578b9196d6bd3c7396278c00e6a49f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 5 Sep 2014 23:47:38 -0700 Subject: [PATCH] Remove some macros from public parser header --- examples/parsers/arithmetic.c | 10 +++++----- examples/parsers/golang.c | 10 +++++----- examples/parsers/javascript.c | 10 +++++----- examples/parsers/json.c | 10 +++++----- include/tree_sitter/parser.h | 11 ----------- src/compiler/generate_code/c_code.cc | 10 +++++----- 6 files changed, 25 insertions(+), 36 deletions(-) diff --git a/examples/parsers/arithmetic.c b/examples/parsers/arithmetic.c index e629bfe3..0b9adfd1 100644 --- a/examples/parsers/arithmetic.c +++ b/examples/parsers/arithmetic.c @@ -23,7 +23,7 @@ enum { ts_aux_sym_7, }; -SYMBOL_NAMES = { +static const char *ts_symbol_names[] = { [ts_builtin_sym_document] = "DOCUMENT", [ts_sym_expression] = "expression", [ts_sym_sum] = "sum", @@ -46,7 +46,7 @@ SYMBOL_NAMES = { [ts_aux_sym_7] = "')'", }; -HIDDEN_SYMBOLS = { +static const int ts_hidden_symbol_flags[SYMBOL_COUNT] = { [ts_aux_sym_1] = 1, [ts_aux_sym_2] = 1, [ts_aux_sym_3] = 1, @@ -56,7 +56,7 @@ HIDDEN_SYMBOLS = { [ts_aux_sym_7] = 1, }; -LEX_FN() { +static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) { START_LEXER(); switch (lex_state) { case 1: @@ -230,7 +230,7 @@ LEX_FN() { } } -LEX_STATES = { +static TSStateId ts_lex_states[STATE_COUNT] = { [0] = 1, [1] = 6, [2] = 6, @@ -268,7 +268,7 @@ LEX_STATES = { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" -PARSE_TABLE = { +static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = { [0] = { [ts_sym_expression] = SHIFT(1), [ts_sym_sum] = SHIFT(2), diff --git a/examples/parsers/golang.c b/examples/parsers/golang.c index db0108b0..d2bed18e 100644 --- a/examples/parsers/golang.c +++ b/examples/parsers/golang.c @@ -91,7 +91,7 @@ enum { ts_aux_sym_23, }; -SYMBOL_NAMES = { +static const char *ts_symbol_names[] = { [ts_builtin_sym_document] = "DOCUMENT", [ts_sym_program] = "program", [ts_sym_package_directive] = "package_directive", @@ -182,7 +182,7 @@ SYMBOL_NAMES = { [ts_aux_sym_23] = "'!'", }; -HIDDEN_SYMBOLS = { +static const int ts_hidden_symbol_flags[SYMBOL_COUNT] = { [ts_sym__func_signature] = 1, [ts_sym__line_break] = 1, [ts_sym__identifier] = 1, @@ -238,7 +238,7 @@ HIDDEN_SYMBOLS = { [ts_aux_sym_23] = 1, }; -LEX_FN() { +static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) { START_LEXER(); switch (lex_state) { case 1: @@ -2243,7 +2243,7 @@ LEX_FN() { } } -LEX_STATES = { +static TSStateId ts_lex_states[STATE_COUNT] = { [0] = 1, [1] = 12, [2] = 14, @@ -2621,7 +2621,7 @@ LEX_STATES = { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" -PARSE_TABLE = { +static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = { [0] = { [ts_sym_program] = SHIFT(1), [ts_sym_package_directive] = SHIFT(2), diff --git a/examples/parsers/javascript.c b/examples/parsers/javascript.c index 2c79b0eb..ff98b2c6 100644 --- a/examples/parsers/javascript.c +++ b/examples/parsers/javascript.c @@ -113,7 +113,7 @@ enum { ts_aux_sym_36, }; -SYMBOL_NAMES = { +static const char *ts_symbol_names[] = { [ts_builtin_sym_document] = "DOCUMENT", [ts_sym_program] = "program", [ts_sym_statement] = "statement", @@ -226,7 +226,7 @@ SYMBOL_NAMES = { [ts_aux_sym_36] = "']'", }; -HIDDEN_SYMBOLS = { +static const int ts_hidden_symbol_flags[SYMBOL_COUNT] = { [ts_sym__line_break] = 1, [ts_aux_sym_program_repeat0] = 1, [ts_aux_sym_statement_block_repeat0] = 1, @@ -295,7 +295,7 @@ HIDDEN_SYMBOLS = { [ts_aux_sym_36] = 1, }; -LEX_FN() { +static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) { START_LEXER(); switch (lex_state) { case 1: @@ -9378,7 +9378,7 @@ LEX_FN() { } } -LEX_STATES = { +static TSStateId ts_lex_states[STATE_COUNT] = { [0] = 1, [1] = 111, [2] = 1, @@ -11596,7 +11596,7 @@ LEX_STATES = { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" -PARSE_TABLE = { +static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = { [0] = { [ts_sym_program] = SHIFT(1), [ts_sym_statement] = SHIFT(2), diff --git a/examples/parsers/json.c b/examples/parsers/json.c index ee1c7dc0..56090219 100644 --- a/examples/parsers/json.c +++ b/examples/parsers/json.c @@ -22,7 +22,7 @@ enum { ts_aux_sym_6, }; -SYMBOL_NAMES = { +static const char *ts_symbol_names[] = { [ts_builtin_sym_document] = "DOCUMENT", [ts_sym_value] = "value", [ts_sym_object] = "object", @@ -44,7 +44,7 @@ SYMBOL_NAMES = { [ts_aux_sym_6] = "']'", }; -HIDDEN_SYMBOLS = { +static const int ts_hidden_symbol_flags[SYMBOL_COUNT] = { [ts_aux_sym_object_repeat0] = 1, [ts_aux_sym_array_repeat0] = 1, [ts_aux_sym_1] = 1, @@ -55,7 +55,7 @@ HIDDEN_SYMBOLS = { [ts_aux_sym_6] = 1, }; -LEX_FN() { +static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) { START_LEXER(); switch (lex_state) { case 1: @@ -362,7 +362,7 @@ LEX_FN() { } } -LEX_STATES = { +static TSStateId ts_lex_states[STATE_COUNT] = { [0] = 1, [1] = 24, [2] = 24, @@ -428,7 +428,7 @@ LEX_STATES = { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" -PARSE_TABLE = { +static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = { [0] = { [ts_sym_value] = SHIFT(1), [ts_sym_object] = SHIFT(2), diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 5deaa0f6..2a8d5ef9 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -78,17 +78,6 @@ struct TSLanguage { TSTree *(*lex_fn)(TSLexer *, TSStateId); }; -#define SYMBOL_NAMES static const char *ts_symbol_names[] - -#define HIDDEN_SYMBOLS static const int ts_hidden_symbol_flags[SYMBOL_COUNT] - -#define LEX_STATES static TSStateId ts_lex_states[STATE_COUNT] - -#define PARSE_TABLE \ - static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] - -#define LEX_FN() static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) - #define DEBUG_LEX(...) \ if (lexer->debug) { \ fprintf(stderr, "LEX " __VA_ARGS__); \ diff --git a/src/compiler/generate_code/c_code.cc b/src/compiler/generate_code/c_code.cc index 60b2d879..73c689c4 100644 --- a/src/compiler/generate_code/c_code.cc +++ b/src/compiler/generate_code/c_code.cc @@ -89,7 +89,7 @@ class CCodeGenerator { } void symbol_names_list() { - line("SYMBOL_NAMES = {"); + line("static const char *ts_symbol_names[] = {"); indent([&]() { for (auto symbol : parse_table.symbols) line("[" + symbol_id(symbol) + "] = \"" + symbol_name(symbol) + "\","); @@ -99,7 +99,7 @@ class CCodeGenerator { } void hidden_symbols_list() { - line("HIDDEN_SYMBOLS = {"); + line("static const int ts_hidden_symbol_flags[SYMBOL_COUNT] = {"); indent([&]() { for (auto &symbol : parse_table.symbols) if (!symbol.is_built_in() && @@ -111,7 +111,7 @@ class CCodeGenerator { } void lex_function() { - line("LEX_FN() {"); + line("static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) {"); indent([&]() { line("START_LEXER();"); switch_on_lex_state(); @@ -121,7 +121,7 @@ class CCodeGenerator { } void lex_states_list() { - line("LEX_STATES = {"); + line("static TSStateId ts_lex_states[STATE_COUNT] = {"); indent([&]() { size_t state_id = 0; for (auto &state : parse_table.states) @@ -137,7 +137,7 @@ class CCodeGenerator { line("#pragma GCC diagnostic push"); line("#pragma GCC diagnostic ignored \"-Wmissing-field-initializers\""); line(); - line("PARSE_TABLE = {"); + line("static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = {"); indent([&]() { for (auto &state : parse_table.states) {