From 7cc15bc523e87f6696c97cbb5f0c814a2440c9cf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 13 Mar 2024 02:31:45 +0000 Subject: [PATCH] Regenerate the parser (a133581) --- src/grammar.json | 1 - src/parser.c | 303 ++++++++++++++++----------------------- src/tree_sitter/alloc.h | 54 +++++++ src/tree_sitter/array.h | 287 ++++++++++++++++++++++++++++++++++++ src/tree_sitter/parser.h | 16 ++- 5 files changed, 474 insertions(+), 187 deletions(-) create mode 100644 src/tree_sitter/alloc.h create mode 100644 src/tree_sitter/array.h diff --git a/src/grammar.json b/src/grammar.json index 6af0e34..78bdb17 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -6341,4 +6341,3 @@ "inline": [], "supertypes": [] } - diff --git a/src/parser.c b/src/parser.c index c54d629..22adb45 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,7 +1,6 @@ -#include +#include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -24,7 +23,7 @@ #define MAX_ALIAS_SEQUENCE_LENGTH 11 #define PRODUCTION_ID_COUNT 9 -enum { +enum ts_symbol_identifiers { sym__alpha_identifier = 1, anon_sym_POUND_BANG = 2, aux_sym_shebang_line_token1 = 3, @@ -16390,9 +16389,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(317) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); @@ -16440,9 +16437,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(1) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16487,9 +16482,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(2) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16537,9 +16530,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(5) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16582,9 +16573,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(6) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16632,9 +16621,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(5) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16677,9 +16664,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(6) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16723,9 +16708,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(548); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(9) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16758,9 +16741,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 't') ADVANCE(596); if (lookahead == 'v') ADVANCE(548); if (lookahead == '{') ADVANCE(333); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(10) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16805,9 +16786,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(534); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(11) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16846,9 +16825,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(548); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(12) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -16894,9 +16871,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(13) if (('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= 'z')) ADVANCE(706); @@ -16934,9 +16909,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(14) if (('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= 'z')) ADVANCE(706); @@ -16981,9 +16954,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(17) if (('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= 'z')) ADVANCE(706); @@ -17021,9 +16992,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(18) if (('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= 'z')) ADVANCE(706); @@ -17068,9 +17037,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(17) if (('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= 'z')) ADVANCE(706); @@ -17108,9 +17075,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(18) if (('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= 'z')) ADVANCE(706); @@ -17146,9 +17111,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(722); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(20) if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); END_STATE(); @@ -17183,9 +17146,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(707); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(21) if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); END_STATE(); @@ -17216,9 +17177,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 't') ADVANCE(538); if (lookahead == 'v') ADVANCE(534); if (lookahead == '{') ADVANCE(333); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(22) if (('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -17243,9 +17202,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '`') ADVANCE(316); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(23) if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); END_STATE(); @@ -17275,9 +17232,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(707); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(24) if (sym__alpha_identifier_character_set_3(lookahead)) ADVANCE(875); END_STATE(); @@ -17299,9 +17254,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'i') ADVANCE(815); if (lookahead == 's') ADVANCE(761); if (lookahead == 'v') ADVANCE(722); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(25) if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); END_STATE(); @@ -17324,9 +17277,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'n') ADVANCE(823); if (lookahead == 's') ADVANCE(761); if (lookahead == 'v') ADVANCE(707); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(26) if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); END_STATE(); @@ -17349,9 +17300,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'n') ADVANCE(823); if (lookahead == 's') ADVANCE(762); if (lookahead == 'v') ADVANCE(707); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(27) if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); END_STATE(); @@ -17377,9 +17326,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 't') ADVANCE(38); if (lookahead == 'v') ADVANCE(36); if (lookahead == '{') ADVANCE(333); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(28) if (('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -17407,9 +17354,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 't') ADVANCE(178); if (lookahead == 'v') ADVANCE(174); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(30) if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'F') || @@ -17419,19 +17364,17 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '/') ADVANCE(29); if (lookahead == 'g') ADVANCE(752); if (lookahead == 's') ADVANCE(762); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(31) if (sym__alpha_identifier_character_set_4(lookahead)) ADVANCE(875); END_STATE(); case 32: if (lookahead == '/') ADVANCE(520); if (lookahead == '\\') ADVANCE(301); - if (lookahead == '\t' || - lookahead == ' ') ADVANCE(521); if (lookahead == '\n' || lookahead == '\r') SKIP(32) + if (('\t' <= lookahead && lookahead <= '\f') || + lookahead == ' ') ADVANCE(521); if (lookahead != 0 && lookahead != '\'') ADVANCE(519); END_STATE(); @@ -19079,9 +19022,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '{') ADVANCE(333); if (lookahead == '|') ADVANCE(307); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(317) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (sym__alpha_identifier_character_set_1(lookahead)) ADVANCE(875); @@ -19127,9 +19068,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'v') ADVANCE(534); if (lookahead == '{') ADVANCE(333); if (lookahead == '}') ADVANCE(334); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(318) if (('1' <= lookahead && lookahead <= '9')) ADVANCE(515); if (('A' <= lookahead && lookahead <= 'Z') || @@ -19152,10 +19091,11 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(aux_sym_shebang_line_token1); if (lookahead == '/') ADVANCE(323); if (lookahead == '\t' || + lookahead == 11 || + lookahead == '\f' || lookahead == ' ') ADVANCE(322); if (lookahead != 0 && - lookahead != '\n' && - lookahead != '\r') ADVANCE(324); + (lookahead < '\n' || '\r' < lookahead)) ADVANCE(324); END_STATE(); case 323: ACCEPT_TOKEN(aux_sym_shebang_line_token1); @@ -20170,10 +20110,11 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(aux_sym_character_literal_token1); if (lookahead == '/') ADVANCE(520); if (lookahead == '\t' || + lookahead == 11 || + lookahead == '\f' || lookahead == ' ') ADVANCE(521); if (lookahead != 0 && - lookahead != '\n' && - lookahead != '\r' && + (lookahead < '\n' || '\r' < lookahead) && lookahead != '\'' && lookahead != '\\') ADVANCE(519); END_STATE(); @@ -22924,9 +22865,7 @@ static bool ts_lex_keywords(TSLexer *lexer, TSStateId state) { if (lookahead == 'w') ADVANCE(16); if (lookahead == 'U' || lookahead == 'u') ADVANCE(17); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(0) END_STATE(); case 1: @@ -33695,83 +33634,6 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [10153] = {.lex_state = 322, .external_lex_state = 8}, }; -enum { - ts_external_token__automatic_semicolon = 0, - ts_external_token__import_list_delimiter = 1, - ts_external_token_safe_nav = 2, - ts_external_token_multiline_comment = 3, - ts_external_token__string_start = 4, - ts_external_token__string_end = 5, - ts_external_token__string_content = 6, -}; - -static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = { - [ts_external_token__automatic_semicolon] = sym__automatic_semicolon, - [ts_external_token__import_list_delimiter] = sym__import_list_delimiter, - [ts_external_token_safe_nav] = sym_safe_nav, - [ts_external_token_multiline_comment] = sym_multiline_comment, - [ts_external_token__string_start] = sym__string_start, - [ts_external_token__string_end] = sym__string_end, - [ts_external_token__string_content] = sym__string_content, -}; - -static const bool ts_external_scanner_states[12][EXTERNAL_TOKEN_COUNT] = { - [1] = { - [ts_external_token__automatic_semicolon] = true, - [ts_external_token__import_list_delimiter] = true, - [ts_external_token_safe_nav] = true, - [ts_external_token_multiline_comment] = true, - [ts_external_token__string_start] = true, - [ts_external_token__string_end] = true, - [ts_external_token__string_content] = true, - }, - [2] = { - [ts_external_token_multiline_comment] = true, - [ts_external_token__string_start] = true, - }, - [3] = { - [ts_external_token_safe_nav] = true, - [ts_external_token_multiline_comment] = true, - [ts_external_token__string_start] = true, - }, - [4] = { - [ts_external_token__automatic_semicolon] = true, - [ts_external_token_safe_nav] = true, - [ts_external_token_multiline_comment] = true, - [ts_external_token__string_start] = true, - }, - [5] = { - [ts_external_token__automatic_semicolon] = true, - [ts_external_token_multiline_comment] = true, - [ts_external_token__string_start] = true, - }, - [6] = { - [ts_external_token_safe_nav] = true, - [ts_external_token_multiline_comment] = true, - }, - [7] = { - [ts_external_token__automatic_semicolon] = true, - [ts_external_token_safe_nav] = true, - [ts_external_token_multiline_comment] = true, - }, - [8] = { - [ts_external_token_multiline_comment] = true, - }, - [9] = { - [ts_external_token__automatic_semicolon] = true, - [ts_external_token_multiline_comment] = true, - }, - [10] = { - [ts_external_token_multiline_comment] = true, - [ts_external_token__string_end] = true, - [ts_external_token__string_content] = true, - }, - [11] = { - [ts_external_token__import_list_delimiter] = true, - [ts_external_token_multiline_comment] = true, - }, -}; - static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [0] = { [ts_builtin_sym_end] = ACTIONS(1), @@ -681748,6 +681610,83 @@ static const TSParseActionEntry ts_parse_actions[] = { [13200] = {.entry = {.count = 1, .reusable = false}}, SHIFT(3569), }; +enum ts_external_scanner_symbol_identifiers { + ts_external_token__automatic_semicolon = 0, + ts_external_token__import_list_delimiter = 1, + ts_external_token_safe_nav = 2, + ts_external_token_multiline_comment = 3, + ts_external_token__string_start = 4, + ts_external_token__string_end = 5, + ts_external_token__string_content = 6, +}; + +static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = { + [ts_external_token__automatic_semicolon] = sym__automatic_semicolon, + [ts_external_token__import_list_delimiter] = sym__import_list_delimiter, + [ts_external_token_safe_nav] = sym_safe_nav, + [ts_external_token_multiline_comment] = sym_multiline_comment, + [ts_external_token__string_start] = sym__string_start, + [ts_external_token__string_end] = sym__string_end, + [ts_external_token__string_content] = sym__string_content, +}; + +static const bool ts_external_scanner_states[12][EXTERNAL_TOKEN_COUNT] = { + [1] = { + [ts_external_token__automatic_semicolon] = true, + [ts_external_token__import_list_delimiter] = true, + [ts_external_token_safe_nav] = true, + [ts_external_token_multiline_comment] = true, + [ts_external_token__string_start] = true, + [ts_external_token__string_end] = true, + [ts_external_token__string_content] = true, + }, + [2] = { + [ts_external_token_multiline_comment] = true, + [ts_external_token__string_start] = true, + }, + [3] = { + [ts_external_token_safe_nav] = true, + [ts_external_token_multiline_comment] = true, + [ts_external_token__string_start] = true, + }, + [4] = { + [ts_external_token__automatic_semicolon] = true, + [ts_external_token_safe_nav] = true, + [ts_external_token_multiline_comment] = true, + [ts_external_token__string_start] = true, + }, + [5] = { + [ts_external_token__automatic_semicolon] = true, + [ts_external_token_multiline_comment] = true, + [ts_external_token__string_start] = true, + }, + [6] = { + [ts_external_token_safe_nav] = true, + [ts_external_token_multiline_comment] = true, + }, + [7] = { + [ts_external_token__automatic_semicolon] = true, + [ts_external_token_safe_nav] = true, + [ts_external_token_multiline_comment] = true, + }, + [8] = { + [ts_external_token_multiline_comment] = true, + }, + [9] = { + [ts_external_token__automatic_semicolon] = true, + [ts_external_token_multiline_comment] = true, + }, + [10] = { + [ts_external_token_multiline_comment] = true, + [ts_external_token__string_end] = true, + [ts_external_token__string_content] = true, + }, + [11] = { + [ts_external_token__import_list_delimiter] = true, + [ts_external_token_multiline_comment] = true, + }, +}; + #ifdef __cplusplus extern "C" { #endif @@ -681758,10 +681697,12 @@ unsigned tree_sitter_kotlin_external_scanner_serialize(void *, char *); void tree_sitter_kotlin_external_scanner_deserialize(void *, const char *, unsigned); #ifdef _WIN32 -#define extern __declspec(dllexport) +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) #endif -extern const TSLanguage *tree_sitter_kotlin(void) { +TS_PUBLIC const TSLanguage *tree_sitter_kotlin() { static const TSLanguage language = { .version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h new file mode 100644 index 0000000..1f4466d --- /dev/null +++ b/src/tree_sitter/alloc.h @@ -0,0 +1,54 @@ +#ifndef TREE_SITTER_ALLOC_H_ +#define TREE_SITTER_ALLOC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +// Allow clients to override allocation functions +#ifdef TREE_SITTER_REUSE_ALLOCATOR + +extern void *(*ts_current_malloc)(size_t); +extern void *(*ts_current_calloc)(size_t, size_t); +extern void *(*ts_current_realloc)(void *, size_t); +extern void (*ts_current_free)(void *); + +#ifndef ts_malloc +#define ts_malloc ts_current_malloc +#endif +#ifndef ts_calloc +#define ts_calloc ts_current_calloc +#endif +#ifndef ts_realloc +#define ts_realloc ts_current_realloc +#endif +#ifndef ts_free +#define ts_free ts_current_free +#endif + +#else + +#ifndef ts_malloc +#define ts_malloc malloc +#endif +#ifndef ts_calloc +#define ts_calloc calloc +#endif +#ifndef ts_realloc +#define ts_realloc realloc +#endif +#ifndef ts_free +#define ts_free free +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ALLOC_H_ diff --git a/src/tree_sitter/array.h b/src/tree_sitter/array.h new file mode 100644 index 0000000..186ba67 --- /dev/null +++ b/src/tree_sitter/array.h @@ -0,0 +1,287 @@ +#ifndef TREE_SITTER_ARRAY_H_ +#define TREE_SITTER_ARRAY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "./alloc.h" + +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(disable : 4101) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +#define Array(T) \ + struct { \ + T *contents; \ + uint32_t size; \ + uint32_t capacity; \ + } + +/// Initialize an array. +#define array_init(self) \ + ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL) + +/// Create an empty array. +#define array_new() \ + { NULL, 0, 0 } + +/// Get a pointer to the element at a given `index` in the array. +#define array_get(self, _index) \ + (assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index]) + +/// Get a pointer to the first element in the array. +#define array_front(self) array_get(self, 0) + +/// Get a pointer to the last element in the array. +#define array_back(self) array_get(self, (self)->size - 1) + +/// Clear the array, setting its size to zero. Note that this does not free any +/// memory allocated for the array's contents. +#define array_clear(self) ((self)->size = 0) + +/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is +/// less than the array's current capacity, this function has no effect. +#define array_reserve(self, new_capacity) \ + _array__reserve((Array *)(self), array_elem_size(self), new_capacity) + +/// Free any memory allocated for this array. Note that this does not free any +/// memory allocated for the array's contents. +#define array_delete(self) _array__delete((Array *)(self)) + +/// Push a new `element` onto the end of the array. +#define array_push(self, element) \ + (_array__grow((Array *)(self), 1, array_elem_size(self)), \ + (self)->contents[(self)->size++] = (element)) + +/// Increase the array's size by `count` elements. +/// New elements are zero-initialized. +#define array_grow_by(self, count) \ + (_array__grow((Array *)(self), count, array_elem_size(self)), \ + memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)), \ + (self)->size += (count)) + +/// Append all elements from one array to the end of another. +#define array_push_all(self, other) \ + array_extend((self), (other)->size, (other)->contents) + +/// Append `count` elements to the end of the array, reading their values from the +/// `contents` pointer. +#define array_extend(self, count, contents) \ + _array__splice( \ + (Array *)(self), array_elem_size(self), (self)->size, \ + 0, count, contents \ + ) + +/// Remove `old_count` elements from the array starting at the given `index`. At +/// the same index, insert `new_count` new elements, reading their values from the +/// `new_contents` pointer. +#define array_splice(self, _index, old_count, new_count, new_contents) \ + _array__splice( \ + (Array *)(self), array_elem_size(self), _index, \ + old_count, new_count, new_contents \ + ) + +/// Insert one `element` into the array at the given `index`. +#define array_insert(self, _index, element) \ + _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element)) + +/// Remove one element from the array at the given `index`. +#define array_erase(self, _index) \ + _array__erase((Array *)(self), array_elem_size(self), _index) + +/// Pop the last element off the array, returning the element by value. +#define array_pop(self) ((self)->contents[--(self)->size]) + +/// Assign the contents of one array to another, reallocating if necessary. +#define array_assign(self, other) \ + _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self)) + +/// Swap one array with another +#define array_swap(self, other) \ + _array__swap((Array *)(self), (Array *)(other)) + +/// Get the size of the array contents +#define array_elem_size(self) (sizeof *(self)->contents) + +/// Search a sorted array for a given `needle` value, using the given `compare` +/// callback to determine the order. +/// +/// If an existing element is found to be equal to `needle`, then the `index` +/// out-parameter is set to the existing value's index, and the `exists` +/// out-parameter is set to true. Otherwise, `index` is set to an index where +/// `needle` should be inserted in order to preserve the sorting, and `exists` +/// is set to false. +#define array_search_sorted_with(self, compare, needle, _index, _exists) \ + _array__search_sorted(self, 0, compare, , needle, _index, _exists) + +/// Search a sorted array for a given `needle` value, using integer comparisons +/// of a given struct field (specified with a leading dot) to determine the order. +/// +/// See also `array_search_sorted_with`. +#define array_search_sorted_by(self, field, needle, _index, _exists) \ + _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists) + +/// Insert a given `value` into a sorted array, using the given `compare` +/// callback to determine the order. +#define array_insert_sorted_with(self, compare, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_with(self, compare, &(value), &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) + +/// Insert a given `value` into a sorted array, using integer comparisons of +/// a given struct field (specified with a leading dot) to determine the order. +/// +/// See also `array_search_sorted_by`. +#define array_insert_sorted_by(self, field, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_by(self, field, (value) field, &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) + +// Private + +typedef Array(void) Array; + +/// This is not what you're looking for, see `array_delete`. +static inline void _array__delete(Array *self) { + if (self->contents) { + ts_free(self->contents); + self->contents = NULL; + self->size = 0; + self->capacity = 0; + } +} + +/// This is not what you're looking for, see `array_erase`. +static inline void _array__erase(Array *self, size_t element_size, + uint32_t index) { + assert(index < self->size); + char *contents = (char *)self->contents; + memmove(contents + index * element_size, contents + (index + 1) * element_size, + (self->size - index - 1) * element_size); + self->size--; +} + +/// This is not what you're looking for, see `array_reserve`. +static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) { + if (new_capacity > self->capacity) { + if (self->contents) { + self->contents = ts_realloc(self->contents, new_capacity * element_size); + } else { + self->contents = ts_malloc(new_capacity * element_size); + } + self->capacity = new_capacity; + } +} + +/// This is not what you're looking for, see `array_assign`. +static inline void _array__assign(Array *self, const Array *other, size_t element_size) { + _array__reserve(self, element_size, other->size); + self->size = other->size; + memcpy(self->contents, other->contents, self->size * element_size); +} + +/// This is not what you're looking for, see `array_swap`. +static inline void _array__swap(Array *self, Array *other) { + Array swap = *other; + *other = *self; + *self = swap; +} + +/// This is not what you're looking for, see `array_push` or `array_grow_by`. +static inline void _array__grow(Array *self, uint32_t count, size_t element_size) { + uint32_t new_size = self->size + count; + if (new_size > self->capacity) { + uint32_t new_capacity = self->capacity * 2; + if (new_capacity < 8) new_capacity = 8; + if (new_capacity < new_size) new_capacity = new_size; + _array__reserve(self, element_size, new_capacity); + } +} + +/// This is not what you're looking for, see `array_splice`. +static inline void _array__splice(Array *self, size_t element_size, + uint32_t index, uint32_t old_count, + uint32_t new_count, const void *elements) { + uint32_t new_size = self->size + new_count - old_count; + uint32_t old_end = index + old_count; + uint32_t new_end = index + new_count; + assert(old_end <= self->size); + + _array__reserve(self, element_size, new_size); + + char *contents = (char *)self->contents; + if (self->size > old_end) { + memmove( + contents + new_end * element_size, + contents + old_end * element_size, + (self->size - old_end) * element_size + ); + } + if (new_count > 0) { + if (elements) { + memcpy( + (contents + index * element_size), + elements, + new_count * element_size + ); + } else { + memset( + (contents + index * element_size), + 0, + new_count * element_size + ); + } + } + self->size += new_count - old_count; +} + +/// A binary search routine, based on Rust's `std::slice::binary_search_by`. +/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`. +#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \ + do { \ + *(_index) = start; \ + *(_exists) = false; \ + uint32_t size = (self)->size - *(_index); \ + if (size == 0) break; \ + int comparison; \ + while (size > 1) { \ + uint32_t half_size = size / 2; \ + uint32_t mid_index = *(_index) + half_size; \ + comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \ + if (comparison <= 0) *(_index) = mid_index; \ + size -= half_size; \ + } \ + comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \ + if (comparison == 0) *(_exists) = true; \ + else if (comparison < 0) *(_index) += 1; \ + } while (0) + +/// Helper macro for the `_sorted_by` routines below. This takes the left (existing) +/// parameter by reference in order to work with the generic sorting function above. +#define _compare_int(a, b) ((int)*(a) - (int)(b)) + +#ifdef _MSC_VER +#pragma warning(default : 4101) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ARRAY_H_ diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 2b14ac1..17b4fde 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -13,9 +13,8 @@ extern "C" { #define ts_builtin_sym_end 0 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 -typedef uint16_t TSStateId; - #ifndef TREE_SITTER_API_H_ +typedef uint16_t TSStateId; typedef uint16_t TSSymbol; typedef uint16_t TSFieldId; typedef struct TSLanguage TSLanguage; @@ -130,9 +129,16 @@ struct TSLanguage { * Lexer Macros */ +#ifdef _MSC_VER +#define UNUSED __pragma(warning(suppress : 4101)) +#else +#define UNUSED __attribute__((unused)) +#endif + #define START_LEXER() \ bool result = false; \ bool skip = false; \ + UNUSED \ bool eof = false; \ int32_t lookahead; \ goto start; \ @@ -166,7 +172,7 @@ struct TSLanguage { * Parse Table Macros */ -#define SMALL_STATE(id) id - LARGE_STATE_COUNT +#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) #define STATE(id) id @@ -176,7 +182,7 @@ struct TSLanguage { {{ \ .shift = { \ .type = TSParseActionTypeShift, \ - .state = state_value \ + .state = (state_value) \ } \ }} @@ -184,7 +190,7 @@ struct TSLanguage { {{ \ .shift = { \ .type = TSParseActionTypeShift, \ - .state = state_value, \ + .state = (state_value), \ .repetition = true \ } \ }}