Get generated parsers building under gcc

This commit is contained in:
Max Brunsfeld 2014-04-08 21:53:13 -07:00
parent 6a0a28f4b3
commit bd5ec68c96
7 changed files with 26 additions and 32 deletions

View file

@ -1,7 +1,7 @@
#include "tree_sitter/parser.h"
STATE_COUNT = 134;
SYMBOL_COUNT = 21;
#define STATE_COUNT 134
#define SYMBOL_COUNT 21
enum {
ts_sym__operand1 = 2,
@ -549,7 +549,7 @@ PARSE_TABLE = {
[1] = {
[ts_aux_sym_token3] = SHIFT(2),
[ts_aux_sym_token4] = SHIFT(100),
[ts_builtin_sym_end] = REDUCE(ts_sym_sum, 1),
[ts_builtin_sym_end] = REDUCE(ts_sym_difference, 1),
},
[2] = {
[ts_sym__operand1] = SHIFT(3),
@ -617,7 +617,7 @@ PARSE_TABLE = {
[ts_builtin_sym_error] = SHIFT(78),
},
[12] = {
[ts_aux_sym_token2] = REDUCE(ts_sym_sum, 1),
[ts_aux_sym_token2] = REDUCE(ts_sym_difference, 1),
[ts_aux_sym_token3] = SHIFT(13),
[ts_aux_sym_token4] = SHIFT(76),
},
@ -689,7 +689,7 @@ PARSE_TABLE = {
[23] = {
[ts_aux_sym_token2] = REDUCE(ts_sym_product, 1),
[ts_aux_sym_token3] = REDUCE(ts_sym_product, 1),
[ts_aux_sym_token4] = REDUCE(ts_sym_product, 1),
[ts_aux_sym_token4] = REDUCE(ts_sym_quotient, 1),
[ts_aux_sym_token5] = SHIFT(24),
[ts_aux_sym_token6] = SHIFT(52),
},
@ -1209,10 +1209,10 @@ PARSE_TABLE = {
},
[102] = {
[ts_aux_sym_token3] = REDUCE(ts_sym_quotient, 1),
[ts_aux_sym_token4] = REDUCE(ts_sym_quotient, 1),
[ts_aux_sym_token4] = REDUCE(ts_sym_product, 1),
[ts_aux_sym_token5] = SHIFT(103),
[ts_aux_sym_token6] = SHIFT(117),
[ts_builtin_sym_end] = REDUCE(ts_sym_quotient, 1),
[ts_builtin_sym_end] = REDUCE(ts_sym_product, 1),
},
[103] = {
[ts_sym__operand2] = SHIFT(104),

View file

@ -1,7 +1,7 @@
#include "tree_sitter/parser.h"
STATE_COUNT = 196;
SYMBOL_COUNT = 52;
#define STATE_COUNT 196
#define SYMBOL_COUNT 52
enum {
ts_sym__func = 2,

View file

@ -1,7 +1,7 @@
#include "tree_sitter/parser.h"
STATE_COUNT = 604;
SYMBOL_COUNT = 55;
#define STATE_COUNT 604
#define SYMBOL_COUNT 55
enum {
ts_sym__break = 2,

View file

@ -1,7 +1,7 @@
#include "tree_sitter/parser.h"
STATE_COUNT = 60;
SYMBOL_COUNT = 18;
#define STATE_COUNT 60
#define SYMBOL_COUNT 18
enum {
ts_sym_array = 2,

View file

@ -31,20 +31,14 @@ extern "C" {
#define DEBUG_PARSE(...)
#endif
#define SYMBOL_COUNT \
static const size_t ts_symbol_count
#define STATE_COUNT \
static const size_t ts_state_count
#define SYMBOL_NAMES \
static const char *ts_symbol_names[ts_symbol_count]
static const char *ts_symbol_names[SYMBOL_COUNT]
#define HIDDEN_SYMBOLS \
static const int hidden_symbol_flags[ts_symbol_count]
static const int hidden_symbol_flags[SYMBOL_COUNT]
#define LEX_STATES \
static state_id ts_lex_states[ts_state_count]
static state_id ts_lex_states[STATE_COUNT]
#define LEX_FN() \
static ts_tree * ts_lex(ts_lexer *lexer, state_id lex_state)
@ -70,26 +64,26 @@ ts_lexer_start_token(lexer);
{ DEBUG_LEX("Lex error: unexpected state %d", LEX_STATE()); return NULL; }
#define PARSE_TABLE \
static const ts_parse_action ts_parse_actions[ts_state_count][ts_symbol_count]
static const ts_parse_action ts_parse_actions[STATE_COUNT][SYMBOL_COUNT]
#define EXPORT_PARSER(constructor_name) \
ts_parser constructor_name() { \
return (ts_parser) { \
.parse_fn = ts_parse, \
.symbol_names = ts_symbol_names, \
.data = ts_lr_parser_make(ts_symbol_count, (const ts_parse_action *)ts_parse_actions, ts_lex_states, hidden_symbol_flags), \
.data = ts_lr_parser_make(SYMBOL_COUNT, (const ts_parse_action *)ts_parse_actions, ts_lex_states, hidden_symbol_flags), \
.free_fn = NULL \
}; \
}
#define SHIFT(to_state_value) \
(ts_parse_action){ .type = ts_parse_action_type_shift, .data = { .to_state = to_state_value } }
{ .type = ts_parse_action_type_shift, .data = { .to_state = to_state_value } }
#define REDUCE(symbol_val, child_count_val) \
(ts_parse_action){ .type = ts_parse_action_type_reduce, .data = { .symbol = symbol_val, .child_count = child_count_val } }
{ .type = ts_parse_action_type_reduce, .data = { .symbol = symbol_val, .child_count = child_count_val } }
#define ACCEPT_INPUT() \
(ts_parse_action){ .type = ts_parse_action_type_accept }
{ .type = ts_parse_action_type_accept }
/*
@ -174,7 +168,7 @@ static ts_tree * ts_lexer_build_node(ts_lexer *lexer, ts_symbol symbol) {
return ts_tree_make_leaf(symbol, size, offset);
}
static const state_id ts_lex_state_error = -1;
#define ts_lex_state_error -1
/*

View file

@ -8,8 +8,8 @@ extern "C" {
#include <stdlib.h>
typedef unsigned int ts_symbol;
static const ts_symbol ts_builtin_sym_error = 0;
static const ts_symbol ts_builtin_sym_end = 1;
#define ts_builtin_sym_error 0
#define ts_builtin_sym_end 1
typedef struct ts_tree ts_tree;
ts_tree * ts_tree_make_leaf(ts_symbol symbol, size_t size, size_t offset);

View file

@ -171,8 +171,8 @@ namespace tree_sitter {
string state_and_symbol_counts() {
return join({
"STATE_COUNT = " + to_string(parse_table.states.size()) + ";",
"SYMBOL_COUNT = " + to_string(parse_table.symbols.size()) + ";"
"#define STATE_COUNT " + to_string(parse_table.states.size()),
"#define SYMBOL_COUNT " + to_string(parse_table.symbols.size())
});
}