tree-sitter-tiger/src/parser.c

346 lines
9.6 KiB
C
Raw Normal View History

#include <tree_sitter/parser.h>
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#define LANGUAGE_VERSION 13
2022-06-01 19:33:42 +02:00
#define STATE_COUNT 9
#define LARGE_STATE_COUNT 2
2022-06-01 19:33:42 +02:00
#define SYMBOL_COUNT 10
#define ALIAS_COUNT 0
2022-06-01 19:33:42 +02:00
#define TOKEN_COUNT 6
#define EXTERNAL_TOKEN_COUNT 0
#define FIELD_COUNT 0
2022-06-01 19:33:42 +02:00
#define MAX_ALIAS_SEQUENCE_LENGTH 3
#define PRODUCTION_ID_COUNT 1
enum {
2022-06-01 19:33:42 +02:00
anon_sym_nil = 1,
sym_integer_literal = 2,
anon_sym_DQUOTE = 3,
aux_sym_string_literal_token1 = 4,
sym_escape_sequence = 5,
sym_source_file = 6,
sym__expr = 7,
sym_string_literal = 8,
aux_sym_string_literal_repeat1 = 9,
};
static const char * const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end",
2022-06-01 19:33:42 +02:00
[anon_sym_nil] = "nil",
[sym_integer_literal] = "integer_literal",
[anon_sym_DQUOTE] = "\"",
[aux_sym_string_literal_token1] = "string_literal_token1",
[sym_escape_sequence] = "escape_sequence",
[sym_source_file] = "source_file",
2022-06-01 19:33:42 +02:00
[sym__expr] = "_expr",
[sym_string_literal] = "string_literal",
[aux_sym_string_literal_repeat1] = "string_literal_repeat1",
};
static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end,
2022-06-01 19:33:42 +02:00
[anon_sym_nil] = anon_sym_nil,
[sym_integer_literal] = sym_integer_literal,
[anon_sym_DQUOTE] = anon_sym_DQUOTE,
[aux_sym_string_literal_token1] = aux_sym_string_literal_token1,
[sym_escape_sequence] = sym_escape_sequence,
[sym_source_file] = sym_source_file,
2022-06-01 19:33:42 +02:00
[sym__expr] = sym__expr,
[sym_string_literal] = sym_string_literal,
[aux_sym_string_literal_repeat1] = aux_sym_string_literal_repeat1,
};
static const TSSymbolMetadata ts_symbol_metadata[] = {
[ts_builtin_sym_end] = {
.visible = false,
.named = true,
},
2022-06-01 19:33:42 +02:00
[anon_sym_nil] = {
.visible = true,
.named = false,
},
2022-06-01 19:33:42 +02:00
[sym_integer_literal] = {
.visible = true,
.named = true,
},
[anon_sym_DQUOTE] = {
.visible = true,
.named = false,
},
[aux_sym_string_literal_token1] = {
.visible = false,
.named = false,
},
[sym_escape_sequence] = {
.visible = true,
.named = true,
},
[sym_source_file] = {
.visible = true,
.named = true,
},
2022-06-01 19:33:42 +02:00
[sym__expr] = {
.visible = false,
.named = true,
},
[sym_string_literal] = {
.visible = true,
.named = true,
},
[aux_sym_string_literal_repeat1] = {
.visible = false,
.named = false,
},
};
static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
[0] = {0},
};
static const uint16_t ts_non_terminal_alias_map[] = {
0,
};
static bool ts_lex(TSLexer *lexer, TSStateId state) {
START_LEXER();
eof = lexer->eof(lexer);
switch (state) {
case 0:
2022-06-01 19:33:42 +02:00
if (eof) ADVANCE(10);
if (lookahead == '"') ADVANCE(13);
if (lookahead == '\\') ADVANCE(6);
if (lookahead == 'n') ADVANCE(2);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
2022-06-01 19:33:42 +02:00
lookahead == ' ') SKIP(9)
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
END_STATE();
case 1:
2022-06-01 19:33:42 +02:00
if (lookahead == '"') ADVANCE(13);
if (lookahead == '\\') ADVANCE(6);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') ADVANCE(14);
if (lookahead != 0) ADVANCE(15);
END_STATE();
case 2:
2022-06-01 19:33:42 +02:00
if (lookahead == 'i') ADVANCE(3);
END_STATE();
case 3:
2022-06-01 19:33:42 +02:00
if (lookahead == 'l') ADVANCE(11);
END_STATE();
case 4:
2022-06-01 19:33:42 +02:00
if (('0' <= lookahead && lookahead <= '7')) ADVANCE(16);
END_STATE();
case 5:
2022-06-01 19:33:42 +02:00
if (('0' <= lookahead && lookahead <= '7')) ADVANCE(4);
END_STATE();
case 6:
2022-06-01 19:33:42 +02:00
if (lookahead == '"' ||
lookahead == '\\' ||
lookahead == 'a' ||
lookahead == 'b' ||
lookahead == 'f' ||
lookahead == 'n' ||
lookahead == 'r' ||
lookahead == 't' ||
lookahead == 'v') ADVANCE(16);
if (lookahead == 'x') ADVANCE(8);
if (('0' <= lookahead && lookahead <= '3')) ADVANCE(5);
END_STATE();
case 7:
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'F') ||
('a' <= lookahead && lookahead <= 'f')) ADVANCE(16);
END_STATE();
case 8:
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'F') ||
('a' <= lookahead && lookahead <= 'f')) ADVANCE(7);
END_STATE();
case 9:
if (eof) ADVANCE(10);
if (lookahead == '"') ADVANCE(13);
if (lookahead == 'n') ADVANCE(2);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') SKIP(9)
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
END_STATE();
case 10:
ACCEPT_TOKEN(ts_builtin_sym_end);
END_STATE();
case 11:
ACCEPT_TOKEN(anon_sym_nil);
END_STATE();
case 12:
ACCEPT_TOKEN(sym_integer_literal);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
END_STATE();
case 13:
ACCEPT_TOKEN(anon_sym_DQUOTE);
END_STATE();
case 14:
ACCEPT_TOKEN(aux_sym_string_literal_token1);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') ADVANCE(14);
if (lookahead != 0 &&
lookahead != '"' &&
lookahead != '\\') ADVANCE(15);
END_STATE();
case 15:
ACCEPT_TOKEN(aux_sym_string_literal_token1);
if (lookahead != 0 &&
lookahead != '"' &&
lookahead != '\\') ADVANCE(15);
END_STATE();
case 16:
ACCEPT_TOKEN(sym_escape_sequence);
END_STATE();
default:
return false;
}
}
static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0},
[1] = {.lex_state = 0},
2022-06-01 19:33:42 +02:00
[2] = {.lex_state = 1},
[3] = {.lex_state = 1},
[4] = {.lex_state = 1},
[5] = {.lex_state = 0},
[6] = {.lex_state = 0},
[7] = {.lex_state = 0},
[8] = {.lex_state = 0},
};
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = {
[ts_builtin_sym_end] = ACTIONS(1),
2022-06-01 19:33:42 +02:00
[anon_sym_nil] = ACTIONS(1),
[sym_integer_literal] = ACTIONS(1),
[anon_sym_DQUOTE] = ACTIONS(1),
[sym_escape_sequence] = ACTIONS(1),
},
[1] = {
2022-06-01 19:33:42 +02:00
[sym_source_file] = STATE(5),
[sym__expr] = STATE(6),
[sym_string_literal] = STATE(6),
[anon_sym_nil] = ACTIONS(3),
[sym_integer_literal] = ACTIONS(3),
[anon_sym_DQUOTE] = ACTIONS(5),
},
};
static const uint16_t ts_small_parse_table[] = {
2022-06-01 19:33:42 +02:00
[0] = 3,
ACTIONS(7), 1,
2022-06-01 19:33:42 +02:00
anon_sym_DQUOTE,
STATE(3), 1,
aux_sym_string_literal_repeat1,
ACTIONS(9), 2,
aux_sym_string_literal_token1,
sym_escape_sequence,
[11] = 3,
ACTIONS(11), 1,
anon_sym_DQUOTE,
STATE(4), 1,
aux_sym_string_literal_repeat1,
ACTIONS(13), 2,
aux_sym_string_literal_token1,
sym_escape_sequence,
[22] = 3,
ACTIONS(15), 1,
anon_sym_DQUOTE,
STATE(4), 1,
aux_sym_string_literal_repeat1,
ACTIONS(17), 2,
aux_sym_string_literal_token1,
sym_escape_sequence,
[33] = 1,
ACTIONS(20), 1,
ts_builtin_sym_end,
[37] = 1,
ACTIONS(22), 1,
ts_builtin_sym_end,
[41] = 1,
ACTIONS(24), 1,
ts_builtin_sym_end,
[45] = 1,
ACTIONS(26), 1,
ts_builtin_sym_end,
};
static const uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(2)] = 0,
2022-06-01 19:33:42 +02:00
[SMALL_STATE(3)] = 11,
[SMALL_STATE(4)] = 22,
[SMALL_STATE(5)] = 33,
[SMALL_STATE(6)] = 37,
[SMALL_STATE(7)] = 41,
[SMALL_STATE(8)] = 45,
};
static const TSParseActionEntry ts_parse_actions[] = {
[0] = {.entry = {.count = 0, .reusable = false}},
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
2022-06-01 19:33:42 +02:00
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6),
[5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
[7] = {.entry = {.count = 1, .reusable = false}}, SHIFT(7),
[9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3),
[11] = {.entry = {.count = 1, .reusable = false}}, SHIFT(8),
[13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4),
[15] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_string_literal_repeat1, 2),
[17] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_string_literal_repeat1, 2), SHIFT_REPEAT(4),
[20] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
[22] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1),
[24] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string_literal, 2),
[26] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string_literal, 3),
};
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#define extern __declspec(dllexport)
#endif
extern const TSLanguage *tree_sitter_tiger(void) {
static const TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,
.alias_count = ALIAS_COUNT,
.token_count = TOKEN_COUNT,
.external_token_count = EXTERNAL_TOKEN_COUNT,
.state_count = STATE_COUNT,
.large_state_count = LARGE_STATE_COUNT,
.production_id_count = PRODUCTION_ID_COUNT,
.field_count = FIELD_COUNT,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.parse_table = &ts_parse_table[0][0],
.small_parse_table = ts_small_parse_table,
.small_parse_table_map = ts_small_parse_table_map,
.parse_actions = ts_parse_actions,
.symbol_names = ts_symbol_names,
.symbol_metadata = ts_symbol_metadata,
.public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map,
.alias_sequences = &ts_alias_sequences[0][0],
.lex_modes = ts_lex_modes,
.lex_fn = ts_lex,
};
return &language;
}
#ifdef __cplusplus
}
#endif