Represent state ids as unsigned shorts

This fixes some signedness conversion warnings
This commit is contained in:
Max Brunsfeld 2014-05-08 13:20:05 -07:00
parent 0a21eee3f0
commit 34137be12d
6 changed files with 4099 additions and 4094 deletions

View file

@ -59,150 +59,150 @@ HIDDEN_SYMBOLS = {
LEX_FN() {
START_LEXER();
switch (lex_state) {
case 0:
case 1:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(0);
if (lookahead == '(')
ADVANCE(1);
if ('0' <= lookahead && lookahead <= '9')
if (lookahead == '(')
ADVANCE(2);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(3);
if (('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z'))
ADVANCE(3);
ADVANCE(4);
LEX_ERROR();
case 1:
ACCEPT_TOKEN(ts_aux_sym_token5);
case 2:
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(2);
ACCEPT_TOKEN(ts_sym_number);
ACCEPT_TOKEN(ts_aux_sym_token5);
case 3:
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(3);
ACCEPT_TOKEN(ts_sym_number);
case 4:
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
(lookahead == '_') ||
('a' <= lookahead && lookahead <= 'z'))
ADVANCE(3);
ADVANCE(4);
ACCEPT_TOKEN(ts_sym_variable);
case 4:
case 5:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(5);
ADVANCE(6);
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(4);
ADVANCE(5);
if (lookahead == '*')
ADVANCE(6);
if (lookahead == '+')
ADVANCE(7);
if (lookahead == '-')
if (lookahead == '+')
ADVANCE(8);
if (lookahead == '/')
if (lookahead == '-')
ADVANCE(9);
if (lookahead == '^')
if (lookahead == '/')
ADVANCE(10);
if (lookahead == '^')
ADVANCE(11);
LEX_ERROR();
case 5:
ACCEPT_TOKEN(ts_builtin_sym_end);
case 6:
ACCEPT_TOKEN(ts_aux_sym_token2);
ACCEPT_TOKEN(ts_builtin_sym_end);
case 7:
ACCEPT_TOKEN(ts_aux_sym_token0);
ACCEPT_TOKEN(ts_aux_sym_token2);
case 8:
ACCEPT_TOKEN(ts_aux_sym_token1);
ACCEPT_TOKEN(ts_aux_sym_token0);
case 9:
ACCEPT_TOKEN(ts_aux_sym_token3);
ACCEPT_TOKEN(ts_aux_sym_token1);
case 10:
ACCEPT_TOKEN(ts_aux_sym_token4);
ACCEPT_TOKEN(ts_aux_sym_token3);
case 11:
ACCEPT_TOKEN(ts_aux_sym_token4);
case 12:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(11);
if (lookahead == ')')
ADVANCE(12);
if (lookahead == ')')
ADVANCE(13);
if (lookahead == '*')
ADVANCE(6);
if (lookahead == '+')
ADVANCE(7);
if (lookahead == '-')
if (lookahead == '+')
ADVANCE(8);
if (lookahead == '/')
if (lookahead == '-')
ADVANCE(9);
if (lookahead == '^')
if (lookahead == '/')
ADVANCE(10);
if (lookahead == '^')
ADVANCE(11);
LEX_ERROR();
case 12:
ACCEPT_TOKEN(ts_aux_sym_token6);
case 13:
ACCEPT_TOKEN(ts_aux_sym_token6);
case 14:
START_TOKEN();
if ((lookahead == '\t') ||
(lookahead == '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(13);
ADVANCE(14);
if (lookahead == ')')
ADVANCE(12);
ADVANCE(13);
LEX_ERROR();
case 14:
case 15:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(5);
ADVANCE(6);
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(14);
ADVANCE(15);
if (lookahead == '(')
ADVANCE(1);
if (lookahead == ')')
ADVANCE(12);
if (lookahead == '*')
ADVANCE(6);
if (lookahead == '+')
ADVANCE(7);
if (lookahead == '-')
ADVANCE(8);
if (lookahead == '/')
ADVANCE(9);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(2);
if (lookahead == ')')
ADVANCE(13);
if (lookahead == '*')
ADVANCE(7);
if (lookahead == '+')
ADVANCE(8);
if (lookahead == '-')
ADVANCE(9);
if (lookahead == '/')
ADVANCE(10);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(3);
if (('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z'))
ADVANCE(3);
ADVANCE(4);
if (lookahead == '^')
ADVANCE(10);
ADVANCE(11);
LEX_ERROR();
case ts_lex_state_error:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(5);
ADVANCE(6);
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(14);
ADVANCE(15);
if (lookahead == '(')
ADVANCE(1);
if (lookahead == ')')
ADVANCE(12);
if (lookahead == '*')
ADVANCE(6);
if (lookahead == '+')
ADVANCE(7);
if (lookahead == '-')
ADVANCE(8);
if (lookahead == '/')
ADVANCE(9);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(2);
if (lookahead == ')')
ADVANCE(13);
if (lookahead == '*')
ADVANCE(7);
if (lookahead == '+')
ADVANCE(8);
if (lookahead == '-')
ADVANCE(9);
if (lookahead == '/')
ADVANCE(10);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(3);
if (('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z'))
ADVANCE(3);
ADVANCE(4);
if (lookahead == '^')
ADVANCE(10);
ADVANCE(11);
LEX_ERROR();
default:
LEX_PANIC();
@ -210,38 +210,38 @@ LEX_FN() {
}
LEX_STATES = {
[0] = 0,
[1] = 4,
[2] = 0,
[3] = 4,
[4] = 0,
[5] = 4,
[6] = 0,
[7] = 4,
[8] = 0,
[9] = 4,
[10] = 0,
[11] = 4,
[12] = 4,
[13] = 0,
[14] = 11,
[15] = 0,
[16] = 11,
[17] = 0,
[18] = 11,
[19] = 0,
[20] = 11,
[21] = 0,
[22] = 11,
[23] = 0,
[24] = 11,
[25] = 11,
[26] = 0,
[27] = 11,
[28] = 11,
[29] = 13,
[30] = 4,
[31] = 13,
[0] = 1,
[1] = 5,
[2] = 1,
[3] = 5,
[4] = 1,
[5] = 5,
[6] = 1,
[7] = 5,
[8] = 1,
[9] = 5,
[10] = 1,
[11] = 5,
[12] = 5,
[13] = 1,
[14] = 12,
[15] = 1,
[16] = 12,
[17] = 1,
[18] = 12,
[19] = 1,
[20] = 12,
[21] = 1,
[22] = 12,
[23] = 1,
[24] = 12,
[25] = 12,
[26] = 1,
[27] = 12,
[28] = 12,
[29] = 14,
[30] = 5,
[31] = 14,
};
#pragma GCC diagnostic push

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -60,103 +60,99 @@ HIDDEN_SYMBOLS = {
LEX_FN() {
START_LEXER();
switch (lex_state) {
case 0:
case 1:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(0);
if (lookahead == '\"')
ADVANCE(1);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(6);
if (lookahead == '[')
ADVANCE(9);
if (lookahead == 'f')
ADVANCE(10);
if (lookahead == 'n')
ADVANCE(15);
if (lookahead == 't')
ADVANCE(19);
if (lookahead == '{')
ADVANCE(23);
LEX_ERROR();
case 1:
if (!((lookahead == '\"') ||
(lookahead == '\\')))
if (lookahead == '\"')
ADVANCE(2);
if (lookahead == '\\')
ADVANCE(4);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(7);
if (lookahead == '[')
ADVANCE(10);
if (lookahead == 'f')
ADVANCE(11);
if (lookahead == 'n')
ADVANCE(16);
if (lookahead == 't')
ADVANCE(20);
if (lookahead == '{')
ADVANCE(24);
LEX_ERROR();
case 2:
if (!((lookahead == '\"') ||
(lookahead == '\\')))
ADVANCE(2);
if (lookahead == '\"')
ADVANCE(3);
if (lookahead == '\\')
ADVANCE(4);
ADVANCE(5);
LEX_ERROR();
case 3:
ACCEPT_TOKEN(ts_sym_string);
case 4:
if (!((lookahead == '\"') ||
(lookahead == '\\')))
ADVANCE(2);
ADVANCE(3);
if (lookahead == '\"')
ADVANCE(5);
if (lookahead == '\\')
ADVANCE(4);
if (lookahead == '\\')
ADVANCE(5);
LEX_ERROR();
case 4:
ACCEPT_TOKEN(ts_sym_string);
case 5:
if (!((lookahead == '\"') ||
(lookahead == '\\')))
ADVANCE(2);
if (lookahead == '\"')
ADVANCE(3);
if (lookahead == '\\')
ADVANCE(4);
ACCEPT_TOKEN(ts_sym_string);
case 6:
if (lookahead == '.')
ADVANCE(7);
if ('0' <= lookahead && lookahead <= '9')
if (lookahead == '\"')
ADVANCE(6);
ACCEPT_TOKEN(ts_sym_number);
case 7:
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(8);
if (lookahead == '\\')
ADVANCE(5);
LEX_ERROR();
case 6:
if (!((lookahead == '\"') ||
(lookahead == '\\')))
ADVANCE(3);
if (lookahead == '\"')
ADVANCE(4);
if (lookahead == '\\')
ADVANCE(5);
ACCEPT_TOKEN(ts_sym_string);
case 7:
if (lookahead == '.')
ADVANCE(8);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(7);
ACCEPT_TOKEN(ts_sym_number);
case 8:
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(8);
ACCEPT_TOKEN(ts_sym_number);
case 9:
ACCEPT_TOKEN(ts_aux_sym_token4);
case 10:
if (lookahead == 'a')
ADVANCE(11);
ADVANCE(9);
LEX_ERROR();
case 9:
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(9);
ACCEPT_TOKEN(ts_sym_number);
case 10:
ACCEPT_TOKEN(ts_aux_sym_token4);
case 11:
if (lookahead == 'l')
if (lookahead == 'a')
ADVANCE(12);
LEX_ERROR();
case 12:
if (lookahead == 's')
if (lookahead == 'l')
ADVANCE(13);
LEX_ERROR();
case 13:
if (lookahead == 'e')
if (lookahead == 's')
ADVANCE(14);
LEX_ERROR();
case 14:
ACCEPT_TOKEN(ts_sym_false);
case 15:
if (lookahead == 'u')
ADVANCE(16);
if (lookahead == 'e')
ADVANCE(15);
LEX_ERROR();
case 15:
ACCEPT_TOKEN(ts_sym_false);
case 16:
if (lookahead == 'l')
if (lookahead == 'u')
ADVANCE(17);
LEX_ERROR();
case 17:
@ -164,71 +160,65 @@ LEX_FN() {
ADVANCE(18);
LEX_ERROR();
case 18:
ACCEPT_TOKEN(ts_sym_null);
case 19:
if (lookahead == 'r')
ADVANCE(20);
if (lookahead == 'l')
ADVANCE(19);
LEX_ERROR();
case 19:
ACCEPT_TOKEN(ts_sym_null);
case 20:
if (lookahead == 'u')
if (lookahead == 'r')
ADVANCE(21);
LEX_ERROR();
case 21:
if (lookahead == 'e')
if (lookahead == 'u')
ADVANCE(22);
LEX_ERROR();
case 22:
ACCEPT_TOKEN(ts_sym_true);
if (lookahead == 'e')
ADVANCE(23);
LEX_ERROR();
case 23:
ACCEPT_TOKEN(ts_aux_sym_token0);
ACCEPT_TOKEN(ts_sym_true);
case 24:
ACCEPT_TOKEN(ts_aux_sym_token0);
case 25:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(25);
if ((lookahead == '\t') ||
(lookahead == '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(24);
LEX_ERROR();
case 25:
ACCEPT_TOKEN(ts_builtin_sym_end);
case 26:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(26);
if (lookahead == '\"')
ADVANCE(1);
if (lookahead == '}')
ADVANCE(27);
LEX_ERROR();
case 27:
ACCEPT_TOKEN(ts_aux_sym_token3);
case 28:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(28);
if (lookahead == ',')
ADVANCE(29);
if (lookahead == '}')
ADVANCE(27);
LEX_ERROR();
case 29:
ACCEPT_TOKEN(ts_aux_sym_token2);
case 30:
START_TOKEN();
if ((lookahead == '\t') ||
(lookahead == '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(25);
LEX_ERROR();
case 26:
ACCEPT_TOKEN(ts_builtin_sym_end);
case 27:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(27);
if (lookahead == '\"')
ADVANCE(2);
if (lookahead == '}')
ADVANCE(28);
LEX_ERROR();
case 28:
ACCEPT_TOKEN(ts_aux_sym_token3);
case 29:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(29);
if (lookahead == ',')
ADVANCE(30);
if (lookahead == '}')
ADVANCE(27);
ADVANCE(28);
LEX_ERROR();
case 30:
ACCEPT_TOKEN(ts_aux_sym_token2);
case 31:
START_TOKEN();
if ((lookahead == '\t') ||
@ -236,8 +226,8 @@ LEX_FN() {
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(31);
if (lookahead == '\"')
ADVANCE(1);
if (lookahead == '}')
ADVANCE(28);
LEX_ERROR();
case 32:
START_TOKEN();
@ -246,118 +236,128 @@ LEX_FN() {
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(32);
if (lookahead == ':')
ADVANCE(33);
if (lookahead == '\"')
ADVANCE(2);
LEX_ERROR();
case 33:
ACCEPT_TOKEN(ts_aux_sym_token1);
case 34:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(34);
if (lookahead == '\"')
ADVANCE(1);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(6);
if (lookahead == '[')
ADVANCE(9);
if (lookahead == ']')
ADVANCE(35);
if (lookahead == 'f')
ADVANCE(10);
if (lookahead == 'n')
ADVANCE(15);
if (lookahead == 't')
ADVANCE(19);
if (lookahead == '{')
ADVANCE(23);
LEX_ERROR();
case 35:
ACCEPT_TOKEN(ts_aux_sym_token5);
case 36:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(36);
if (lookahead == ',')
ADVANCE(29);
if (lookahead == ']')
ADVANCE(35);
LEX_ERROR();
case 37:
START_TOKEN();
if ((lookahead == '\t') ||
(lookahead == '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(37);
if (lookahead == ']')
ADVANCE(35);
ADVANCE(33);
if (lookahead == ':')
ADVANCE(34);
LEX_ERROR();
case 38:
case 34:
ACCEPT_TOKEN(ts_aux_sym_token1);
case 35:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(25);
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(38);
if (lookahead == '\"')
ADVANCE(1);
if (lookahead == ',')
ADVANCE(29);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(6);
if (lookahead == ':')
ADVANCE(33);
if (lookahead == '[')
ADVANCE(9);
if (lookahead == ']')
ADVANCE(35);
if (lookahead == 'f')
if (lookahead == '\"')
ADVANCE(2);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(7);
if (lookahead == '[')
ADVANCE(10);
if (lookahead == ']')
ADVANCE(36);
if (lookahead == 'f')
ADVANCE(11);
if (lookahead == 'n')
ADVANCE(15);
ADVANCE(16);
if (lookahead == 't')
ADVANCE(19);
ADVANCE(20);
if (lookahead == '{')
ADVANCE(23);
ADVANCE(24);
LEX_ERROR();
case 36:
ACCEPT_TOKEN(ts_aux_sym_token5);
case 37:
START_TOKEN();
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(37);
if (lookahead == ',')
ADVANCE(30);
if (lookahead == ']')
ADVANCE(36);
LEX_ERROR();
case 38:
START_TOKEN();
if ((lookahead == '\t') ||
(lookahead == '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(38);
if (lookahead == ']')
ADVANCE(36);
LEX_ERROR();
case 39:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(26);
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(39);
if (lookahead == '\"')
ADVANCE(2);
if (lookahead == ',')
ADVANCE(30);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(7);
if (lookahead == ':')
ADVANCE(34);
if (lookahead == '[')
ADVANCE(10);
if (lookahead == ']')
ADVANCE(36);
if (lookahead == 'f')
ADVANCE(11);
if (lookahead == 'n')
ADVANCE(16);
if (lookahead == 't')
ADVANCE(20);
if (lookahead == '{')
ADVANCE(24);
if (lookahead == '}')
ADVANCE(27);
ADVANCE(28);
LEX_ERROR();
case ts_lex_state_error:
START_TOKEN();
if (lookahead == '\0')
ADVANCE(25);
ADVANCE(26);
if (('\t' <= lookahead && lookahead <= '\n') ||
(lookahead == '\r') ||
(lookahead == ' '))
ADVANCE(38);
ADVANCE(39);
if (lookahead == '\"')
ADVANCE(1);
ADVANCE(2);
if (lookahead == ',')
ADVANCE(29);
ADVANCE(30);
if ('0' <= lookahead && lookahead <= '9')
ADVANCE(6);
ADVANCE(7);
if (lookahead == ':')
ADVANCE(33);
ADVANCE(34);
if (lookahead == '[')
ADVANCE(9);
if (lookahead == ']')
ADVANCE(35);
if (lookahead == 'f')
ADVANCE(10);
if (lookahead == ']')
ADVANCE(36);
if (lookahead == 'f')
ADVANCE(11);
if (lookahead == 'n')
ADVANCE(15);
ADVANCE(16);
if (lookahead == 't')
ADVANCE(19);
ADVANCE(20);
if (lookahead == '{')
ADVANCE(23);
ADVANCE(24);
if (lookahead == '}')
ADVANCE(27);
ADVANCE(28);
LEX_ERROR();
default:
LEX_PANIC();
@ -365,66 +365,66 @@ LEX_FN() {
}
LEX_STATES = {
[0] = 0,
[1] = 24,
[2] = 24,
[3] = 26,
[4] = 28,
[5] = 30,
[6] = 24,
[7] = 31,
[8] = 28,
[9] = 30,
[10] = 32,
[11] = 0,
[12] = 28,
[13] = 30,
[14] = 28,
[15] = 26,
[16] = 28,
[17] = 30,
[18] = 28,
[19] = 32,
[20] = 0,
[21] = 28,
[22] = 30,
[23] = 28,
[24] = 34,
[25] = 36,
[26] = 37,
[27] = 28,
[28] = 0,
[29] = 36,
[30] = 37,
[31] = 36,
[32] = 26,
[33] = 28,
[34] = 30,
[35] = 36,
[36] = 32,
[37] = 0,
[38] = 28,
[39] = 30,
[40] = 36,
[41] = 36,
[42] = 34,
[43] = 36,
[44] = 37,
[45] = 36,
[46] = 36,
[47] = 28,
[48] = 28,
[49] = 32,
[50] = 0,
[51] = 28,
[52] = 30,
[53] = 24,
[54] = 24,
[55] = 34,
[56] = 36,
[57] = 37,
[58] = 24,
[59] = 24,
[0] = 1,
[1] = 25,
[2] = 25,
[3] = 27,
[4] = 29,
[5] = 31,
[6] = 25,
[7] = 32,
[8] = 29,
[9] = 31,
[10] = 33,
[11] = 1,
[12] = 29,
[13] = 31,
[14] = 29,
[15] = 27,
[16] = 29,
[17] = 31,
[18] = 29,
[19] = 33,
[20] = 1,
[21] = 29,
[22] = 31,
[23] = 29,
[24] = 35,
[25] = 37,
[26] = 38,
[27] = 29,
[28] = 1,
[29] = 37,
[30] = 38,
[31] = 37,
[32] = 27,
[33] = 29,
[34] = 31,
[35] = 37,
[36] = 33,
[37] = 1,
[38] = 29,
[39] = 31,
[40] = 37,
[41] = 37,
[42] = 35,
[43] = 37,
[44] = 38,
[45] = 37,
[46] = 37,
[47] = 29,
[48] = 29,
[49] = 33,
[50] = 1,
[51] = 29,
[52] = 31,
[53] = 25,
[54] = 25,
[55] = 35,
[56] = 37,
[57] = 38,
[58] = 25,
[59] = 25,
};
#pragma GCC diagnostic push

View file

@ -34,10 +34,10 @@ static const int hidden_symbol_flags[SYMBOL_COUNT]
static const int ubiquitous_symbol_flags[SYMBOL_COUNT]
#define LEX_STATES \
static state_id ts_lex_states[STATE_COUNT]
static ts_state_id ts_lex_states[STATE_COUNT]
#define LEX_FN() \
static ts_tree * ts_lex(ts_lexer *lexer, state_id lex_state)
static ts_tree * ts_lex(ts_lexer *lexer, ts_state_id lex_state)
#define START_LEXER() \
char lookahead; \
@ -92,12 +92,12 @@ ts_parser constructor_name() { \
/*
* Stack
*/
typedef short state_id;
typedef unsigned short ts_state_id;
typedef struct {
size_t size;
struct {
ts_tree *node;
state_id state;
ts_state_id state;
} *entries;
} ts_stack;
@ -105,8 +105,8 @@ ts_stack ts_stack_make();
ts_tree * ts_stack_root(const ts_stack *stack);
ts_tree * ts_stack_reduce(ts_stack *stack, ts_symbol symbol, int immediate_child_count, const int *hidden_symbol_flags, const int *ubiquitous_symbol_flags);
void ts_stack_shrink(ts_stack *stack, size_t new_size);
void ts_stack_push(ts_stack *stack, state_id state, ts_tree *node);
state_id ts_stack_top_state(const ts_stack *stack);
void ts_stack_push(ts_stack *stack, ts_state_id state, ts_tree *node);
ts_state_id ts_stack_top_state(const ts_stack *stack);
ts_tree * ts_stack_top_node(const ts_stack *stack);
size_t ts_stack_right_position(const ts_stack *stack);
@ -171,7 +171,7 @@ static ts_tree * ts_lexer_build_node(ts_lexer *lexer, ts_symbol symbol) {
return ts_tree_make_leaf(symbol, size, offset);
}
#define ts_lex_state_error -1
#define ts_lex_state_error 0
/*
@ -187,7 +187,7 @@ typedef enum {
typedef struct {
ts_parse_action_type type;
union {
int to_state;
ts_state_id to_state;
struct {
ts_symbol symbol;
unsigned short child_count;
@ -215,14 +215,14 @@ typedef struct {
ts_tree *lookahead;
ts_tree *next_lookahead;
const ts_parse_action *parse_table;
const state_id *lex_states;
const ts_state_id *lex_states;
size_t symbol_count;
} ts_lr_parser;
static ts_lr_parser *
ts_lr_parser_make(size_t symbol_count,
const ts_parse_action *parse_table,
const state_id *lex_states,
const ts_state_id *lex_states,
const int *hidden_symbol_flags,
const int *ubiquitous_symbol_flags) {
ts_lr_parser *result = malloc(sizeof(ts_lr_parser));
@ -236,7 +236,7 @@ ts_lr_parser_make(size_t symbol_count,
return result;
}
static const ts_parse_action * ts_lr_parser_table_actions(ts_lr_parser *parser, state_id state) {
static const ts_parse_action * ts_lr_parser_table_actions(ts_lr_parser *parser, ts_state_id state) {
return parser->parse_table + (state * parser->symbol_count);
}
@ -261,8 +261,8 @@ static size_t ts_lr_parser_breakdown_stack(ts_lr_parser *parser, ts_input_edit *
for (size_t i = 0; i < child_count && position < edit->position; i++) {
ts_tree *child = children[i];
state_id state = ts_stack_top_state(stack);
state_id next_state = ts_lr_parser_table_actions(parser, state)[ts_tree_symbol(child)].data.to_state;
ts_state_id state = ts_stack_top_state(stack);
ts_state_id next_state = ts_lr_parser_table_actions(parser, state)[ts_tree_symbol(child)].data.to_state;
ts_stack_push(stack, next_state, child);
ts_tree_retain(child);
position += ts_tree_total_size(child);
@ -287,7 +287,7 @@ static void ts_lr_parser_initialize(ts_lr_parser *parser, ts_input input, ts_inp
ts_lexer_advance(&parser->lexer);
}
static void ts_lr_parser_shift(ts_lr_parser *parser, state_id parse_state) {
static void ts_lr_parser_shift(ts_lr_parser *parser, ts_state_id parse_state) {
ts_stack_push(&parser->stack, parse_state, parser->lookahead);
parser->lookahead = parser->next_lookahead;
parser->next_lookahead = NULL;
@ -335,11 +335,12 @@ static int ts_lr_parser_handle_error(ts_lr_parser *parser) {
* Unwind the stack, looking for a state in which this token
* may appear after an error.
*/
for (long i = parser->stack.size - 1; i >= 0; i--) {
state_id stack_state = parser->stack.entries[i].state;
for (size_t j = 0; j < parser->stack.size; j++) {
size_t i = parser->stack.size - 1 - j;
ts_state_id stack_state = parser->stack.entries[i].state;
ts_parse_action action_on_error = ts_lr_parser_table_actions(parser, stack_state)[ts_builtin_sym_error];
if (action_on_error.type == ts_parse_action_type_shift) {
state_id state_after_error = action_on_error.data.to_state;
ts_state_id state_after_error = action_on_error.data.to_state;
if (ts_lr_parser_table_actions(parser, state_after_error)[ts_tree_symbol(parser->lookahead)].type != ts_parse_action_type_error) {
ts_stack_shrink(&parser->stack, i + 1);
ts_stack_push(&parser->stack, state_after_error, error);
@ -355,7 +356,7 @@ static const ts_tree * ts_parse(void *data, ts_input input, ts_input_edit *edit)
ts_lr_parser *parser = (ts_lr_parser *)data;
ts_lr_parser_initialize(parser, input, edit);
while (!done) {
state_id state = ts_stack_top_state(&parser->stack);
ts_state_id state = ts_stack_top_state(&parser->stack);
if (!parser->lookahead)
parser->lookahead = ts_lex(&parser->lexer, parser->lex_states[state]);
ts_parse_action action = ts_lr_parser_table_actions(parser, state)[ts_tree_symbol(parser->lookahead)];

View file

@ -102,6 +102,10 @@ namespace tree_sitter {
return "ts_sym_" + name;
}
}
string lex_state_index(size_t i) {
return to_string(i + 1);
}
string symbol_name(const rules::Symbol &symbol) {
if (symbol.is_built_in()) {
@ -163,7 +167,7 @@ namespace tree_sitter {
const set<rules::CharacterSet> &expected_inputs) {
switch (action.type) {
case LexActionTypeAdvance:
return "ADVANCE(" + to_string(action.state_index) + ");";
return "ADVANCE(" + lex_state_index(action.state_index) + ");";
case LexActionTypeAccept:
return "ACCEPT_TOKEN(" + symbol_id(action.symbol) + ");";
case LexActionTypeError:
@ -189,7 +193,7 @@ namespace tree_sitter {
string switch_on_lex_state() {
string body = "";
for (size_t i = 0; i < lex_table.states.size(); i++)
body += _case(std::to_string(i), code_for_lex_state(lex_table.states[i]));
body += _case(lex_state_index(i), code_for_lex_state(lex_table.states[i]));
body += _case("ts_lex_state_error", code_for_lex_state(lex_table.error_state));
body += _default("LEX_PANIC();");
return _switch("lex_state", body);
@ -268,7 +272,7 @@ namespace tree_sitter {
return join({
"LEX_STATES = {",
indent(join(map_to_string<ParseState>(parse_table.states, [&](ParseState state) {
return "[" + to_string(state_id++) + "] = " + to_string(state.lex_state_id) + ",";
return "[" + to_string(state_id++) + "] = " + lex_state_index(state.lex_state_id) + ",";
}))),
"};"
});