From a210f66b4f2d23e523ca2b4f90ab739648b62b0f Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 5 May 2024 20:25:41 -0400 Subject: [PATCH] chore: generate --- src/grammar.json | 1 - src/parser.c | 238 +++++++++++++++++--------------- src/tree_sitter/alloc.h | 54 ++++++++ src/tree_sitter/array.h | 290 +++++++++++++++++++++++++++++++++++++++ src/tree_sitter/parser.h | 51 +++++-- 5 files changed, 511 insertions(+), 123 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 b221c50..e33020e 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -577,4 +577,3 @@ "inline": [], "supertypes": [] } - diff --git a/src/parser.c b/src/parser.c index b673c26..8bba29f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,7 +1,6 @@ #include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -305,7 +304,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { switch (state) { case 0: if (eof) ADVANCE(21); - if (lookahead == '\n') SKIP(19) + if (lookahead == '\n') SKIP(19); if (lookahead == '#') ADVANCE(131); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(129); @@ -317,7 +316,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '}') ADVANCE(24); if (lookahead == '~') ADVANCE(132); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(20) + lookahead == ' ') SKIP(20); if (lookahead == '$' || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -326,33 +325,33 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '*') ADVANCE(138); END_STATE(); case 1: - if (lookahead == '\n') SKIP(1) - if (lookahead == '*') SKIP(1) + if (lookahead == '\n') SKIP(1); + if (lookahead == '*') SKIP(1); if (lookahead == '/') ADVANCE(139); if (lookahead == '@') ADVANCE(18); if (lookahead == ']') ADVANCE(134); if (lookahead == '\t' || - lookahead == ' ') SKIP(1) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(2) + lookahead == ' ') SKIP(1); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(2); END_STATE(); case 2: - if (lookahead == '\n') SKIP(1) + if (lookahead == '\n') SKIP(1); if (lookahead == '/') ADVANCE(139); if (lookahead == '@') ADVANCE(18); if (lookahead == ']') ADVANCE(134); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(2) + lookahead == ' ') SKIP(2); END_STATE(); case 3: - if (lookahead == '\n') SKIP(3) - if (lookahead == '*') SKIP(3) + if (lookahead == '\n') SKIP(3); + if (lookahead == '*') SKIP(3); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '[') ADVANCE(133); if (lookahead == '{') ADVANCE(22); if (lookahead == '\t' || - lookahead == ' ') SKIP(3) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(4) + lookahead == ' ') SKIP(3); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(4); if (lookahead == '$' || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -361,13 +360,13 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '}') ADVANCE(138); END_STATE(); case 4: - if (lookahead == '\n') SKIP(3) + if (lookahead == '\n') SKIP(3); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '[') ADVANCE(133); if (lookahead == '{') ADVANCE(22); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(4) + lookahead == ' ') SKIP(4); if (lookahead == '$' || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -377,23 +376,24 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '}') ADVANCE(138); END_STATE(); case 5: - if (lookahead == '\n') SKIP(5) + if (lookahead == '\n') SKIP(5); if (lookahead == '#') ADVANCE(131); - if (lookahead == '*') SKIP(5) + if (lookahead == '*') SKIP(5); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(140); if (lookahead == ':') ADVANCE(127); if (lookahead == '@') ADVANCE(17); if (lookahead == '~') ADVANCE(132); if (lookahead == '\t' || - lookahead == ' ') SKIP(5) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(6) + lookahead == ' ') SKIP(5); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(6); if (lookahead != 0 && lookahead != '{' && - lookahead != '}') ADVANCE(138); + lookahead != '}' && + lookahead != '~') ADVANCE(138); END_STATE(); case 6: - if (lookahead == '\n') SKIP(5) + if (lookahead == '\n') SKIP(5); if (lookahead == '#') ADVANCE(131); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(140); @@ -401,14 +401,15 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '@') ADVANCE(17); if (lookahead == '~') ADVANCE(132); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(6) + lookahead == ' ') SKIP(6); if (lookahead != 0 && lookahead != '*' && lookahead != '{' && - lookahead != '}') ADVANCE(138); + lookahead != '}' && + lookahead != '~') ADVANCE(138); END_STATE(); case 7: - if (lookahead == '\n') SKIP(5) + if (lookahead == '\n') SKIP(5); if (lookahead == '#') ADVANCE(131); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(128); @@ -416,104 +417,107 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '@') ADVANCE(17); if (lookahead == '~') ADVANCE(132); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(6) + lookahead == ' ') SKIP(6); if (lookahead != 0 && lookahead != '*' && lookahead != '{' && - lookahead != '}') ADVANCE(138); + lookahead != '}' && + lookahead != '~') ADVANCE(138); END_STATE(); case 8: - if (lookahead == '\n') SKIP(8) - if (lookahead == '*') SKIP(8) + if (lookahead == '\n') SKIP(8); + if (lookahead == '*') SKIP(8); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '{') ADVANCE(23); if (lookahead == '\t' || - lookahead == ' ') SKIP(8) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(9) + lookahead == ' ') SKIP(8); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(9); if (lookahead != 0 && lookahead != '}') ADVANCE(138); END_STATE(); case 9: - if (lookahead == '\n') SKIP(8) + if (lookahead == '\n') SKIP(8); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '{') ADVANCE(23); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(9) + lookahead == ' ') SKIP(9); if (lookahead != 0 && lookahead != '*' && lookahead != '}') ADVANCE(138); END_STATE(); case 10: - if (lookahead == '\n') SKIP(10) + if (lookahead == '\n') SKIP(10); if (lookahead == '#') ADVANCE(131); - if (lookahead == '*') SKIP(10) + if (lookahead == '*') SKIP(10); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '~') ADVANCE(132); if (lookahead == '\t' || - lookahead == ' ') SKIP(10) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(11) + lookahead == ' ') SKIP(10); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(11); if (lookahead != 0 && lookahead != '{' && - lookahead != '}') ADVANCE(138); + lookahead != '}' && + lookahead != '~') ADVANCE(138); END_STATE(); case 11: - if (lookahead == '\n') SKIP(10) + if (lookahead == '\n') SKIP(10); if (lookahead == '#') ADVANCE(131); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '~') ADVANCE(132); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(11) + lookahead == ' ') SKIP(11); if (lookahead != 0 && lookahead != '*' && lookahead != '{' && - lookahead != '}') ADVANCE(138); + lookahead != '}' && + lookahead != '~') ADVANCE(138); END_STATE(); case 12: - if (lookahead == '\n') SKIP(12) - if (lookahead == '*') SKIP(12) + if (lookahead == '\n') SKIP(12); + if (lookahead == '*') SKIP(12); if (lookahead == '{') ADVANCE(23); if (lookahead == '}') ADVANCE(24); if (lookahead == '\t' || - lookahead == ' ') SKIP(12) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(13) + lookahead == ' ') SKIP(12); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(13); if (lookahead != 0 && lookahead != '@') ADVANCE(138); END_STATE(); case 13: - if (lookahead == '\n') SKIP(12) + if (lookahead == '\n') SKIP(12); if (lookahead == '{') ADVANCE(23); if (lookahead == '}') ADVANCE(24); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(13) + lookahead == ' ') SKIP(13); if (lookahead != 0 && lookahead != '*' && lookahead != '@') ADVANCE(138); END_STATE(); case 14: - if (lookahead == '\n') SKIP(14) - if (lookahead == '*') SKIP(14) + if (lookahead == '\n') SKIP(14); + if (lookahead == '*') SKIP(14); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '{') ADVANCE(22); if (lookahead == '\t' || - lookahead == ' ') SKIP(14) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(15) + lookahead == ' ') SKIP(14); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(15); if (lookahead != 0 && lookahead != '}') ADVANCE(138); END_STATE(); case 15: - if (lookahead == '\n') SKIP(14) + if (lookahead == '\n') SKIP(14); if (lookahead == '/') ADVANCE(140); if (lookahead == '@') ADVANCE(17); if (lookahead == '{') ADVANCE(22); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(15) + lookahead == ' ') SKIP(15); if (lookahead != 0 && lookahead != '*' && lookahead != '}') ADVANCE(138); @@ -526,17 +530,19 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '}') ADVANCE(16); END_STATE(); case 17: - if (lookahead == 'a') ADVANCE(43); - if (lookahead == 'b') ADVANCE(86); - if (lookahead == 'c') ADVANCE(33); - if (lookahead == 'e') ADVANCE(121); - if (lookahead == 'f') ADVANCE(66); - if (lookahead == 'm') ADVANCE(64); - if (lookahead == 'n') ADVANCE(34); - if (lookahead == 'p') ADVANCE(38); - if (lookahead == 'r') ADVANCE(50); - if (lookahead == 's') ADVANCE(36); - if (lookahead == 't') ADVANCE(63); + ADVANCE_MAP( + 'a', 43, + 'b', 86, + 'c', 33, + 'e', 121, + 'f', 66, + 'm', 64, + 'n', 34, + 'p', 38, + 'r', 50, + 's', 36, + 't', 63, + ); if (('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || ('d' <= lookahead && lookahead <= 'z')) ADVANCE(126); @@ -548,9 +554,9 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 19: if (eof) ADVANCE(21); - if (lookahead == '\n') SKIP(19) + if (lookahead == '\n') SKIP(19); if (lookahead == '#') ADVANCE(131); - if (lookahead == '*') SKIP(19) + if (lookahead == '*') SKIP(19); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(141); if (lookahead == ':') ADVANCE(127); @@ -561,8 +567,8 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '}') ADVANCE(24); if (lookahead == '~') ADVANCE(132); if (lookahead == '\t' || - lookahead == ' ') SKIP(19) - if ((11 <= lookahead && lookahead <= '\r')) SKIP(20) + lookahead == ' ') SKIP(19); + if ((0x0b <= lookahead && lookahead <= '\r')) SKIP(20); if (lookahead == '$' || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -571,7 +577,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 20: if (eof) ADVANCE(21); - if (lookahead == '\n') SKIP(19) + if (lookahead == '\n') SKIP(19); if (lookahead == '#') ADVANCE(131); if (lookahead == '.') ADVANCE(130); if (lookahead == '/') ADVANCE(141); @@ -583,7 +589,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '}') ADVANCE(24); if (lookahead == '~') ADVANCE(132); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(20) + lookahead == ' ') SKIP(20); if (lookahead == '$' || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || @@ -1982,82 +1988,82 @@ static const TSParseActionEntry ts_parse_actions[] = { [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), [5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36), - [7] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 1), + [7] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 1, 0, 0), [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(47), [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), [13] = {.entry = {.count = 1, .reusable = false}}, SHIFT(6), - [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 1), - [17] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 4), - [19] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 4), - [21] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__expression, 1), + [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 1, 0, 0), + [17] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 4, 0, 0), + [19] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 4, 0, 0), + [21] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__expression, 1, 0, 0), [23] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), [25] = {.entry = {.count = 1, .reusable = true}}, SHIFT(41), - [27] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expression, 1), - [29] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_member_expression, 3), - [31] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_member_expression, 3), + [27] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expression, 1, 0, 0), + [29] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_member_expression, 3, 0, 0), + [31] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_member_expression, 3, 0, 0), [33] = {.entry = {.count = 1, .reusable = false}}, SHIFT(45), [35] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), - [37] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_description, 1), + [37] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_description, 1, 0, 0), [39] = {.entry = {.count = 1, .reusable = false}}, SHIFT(10), - [41] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_description, 1), - [43] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2), SHIFT_REPEAT(45), - [46] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_description_repeat1, 2), SHIFT_REPEAT(7), - [49] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2), - [51] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2), SHIFT_REPEAT(7), - [54] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_description_repeat1, 2), - [56] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 2), + [41] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_description, 1, 0, 0), + [43] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), SHIFT_REPEAT(45), + [46] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), SHIFT_REPEAT(7), + [49] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), + [51] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), SHIFT_REPEAT(7), + [54] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), + [56] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 2, 0, 0), [58] = {.entry = {.count = 1, .reusable = true}}, SHIFT(34), - [60] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 2), - [62] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 5), - [64] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 5), + [60] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 2, 0, 0), + [62] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 5, 0, 0), + [64] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 5, 0, 0), [66] = {.entry = {.count = 1, .reusable = true}}, SHIFT(7), - [68] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_description, 2), + [68] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_description, 2, 0, 0), [70] = {.entry = {.count = 1, .reusable = false}}, SHIFT(7), - [72] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_description, 2), + [72] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_description, 2, 0, 0), [74] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2), [76] = {.entry = {.count = 1, .reusable = false}}, SHIFT(17), [78] = {.entry = {.count = 1, .reusable = false}}, SHIFT(27), [80] = {.entry = {.count = 1, .reusable = true}}, SHIFT(49), - [82] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_path_expression, 3), - [84] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_path_expression, 3), - [86] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_qualified_expression, 3), - [88] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_qualified_expression, 3), - [90] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_optional_identifier, 3), - [92] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_optional_identifier, 3), - [94] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_inline_tag, 4), - [96] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_inline_tag, 4), + [82] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_path_expression, 3, 0, 0), + [84] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_path_expression, 3, 0, 0), + [86] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_qualified_expression, 3, 0, 0), + [88] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_qualified_expression, 3, 0, 0), + [90] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_optional_identifier, 3, 0, 0), + [92] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_optional_identifier, 3, 0, 0), + [94] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_inline_tag, 4, 0, 0), + [96] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_inline_tag, 4, 0, 0), [98] = {.entry = {.count = 1, .reusable = true}}, SHIFT(46), [100] = {.entry = {.count = 1, .reusable = true}}, SHIFT(44), [102] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), - [104] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(2), - [107] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(17), - [110] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(27), - [113] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2), + [104] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(2), + [107] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(17), + [110] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(27), + [113] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), [115] = {.entry = {.count = 1, .reusable = false}}, SHIFT(50), [117] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), [119] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), - [121] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2), SHIFT_REPEAT(50), - [124] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_description_repeat1, 2), SHIFT_REPEAT(24), - [127] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 6), - [129] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 6), - [131] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 3), - [133] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 3), + [121] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), SHIFT_REPEAT(50), + [124] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_description_repeat1, 2, 0, 0), SHIFT_REPEAT(24), + [127] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 6, 0, 0), + [129] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 6, 0, 0), + [131] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tag, 3, 0, 0), + [133] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tag, 3, 0, 0), [135] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), [137] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), [139] = {.entry = {.count = 1, .reusable = true}}, SHIFT(43), - [141] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 4), + [141] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 4, 0, 0), [143] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26), [145] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), [147] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), [149] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), [151] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), [153] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), - [155] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 3), + [155] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 3, 0, 0), [157] = {.entry = {.count = 1, .reusable = true}}, SHIFT(35), [159] = {.entry = {.count = 1, .reusable = true}}, SHIFT(38), [161] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42), [163] = {.entry = {.count = 1, .reusable = true}}, SHIFT(32), - [165] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 2), + [165] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 2, 0, 0), [167] = {.entry = {.count = 1, .reusable = true}}, SHIFT(33), }; @@ -2084,11 +2090,15 @@ bool tree_sitter_jsdoc_external_scanner_scan(void *, TSLexer *, const bool *); unsigned tree_sitter_jsdoc_external_scanner_serialize(void *, char *); void tree_sitter_jsdoc_external_scanner_deserialize(void *, const char *, unsigned); -#ifdef _WIN32 -#define extern __declspec(dllexport) +#ifdef TREE_SITTER_HIDE_SYMBOLS +#define TS_PUBLIC +#elif defined(_WIN32) +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) #endif -extern const TSLanguage *tree_sitter_jsdoc(void) { +TS_PUBLIC const TSLanguage *tree_sitter_jsdoc(void) { 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..15a3b23 --- /dev/null +++ b/src/tree_sitter/array.h @@ -0,0 +1,290 @@ +#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) \ + do { \ + if ((count) == 0) break; \ + _array__grow((Array *)(self), count, array_elem_size(self)); \ + memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \ + (self)->size += (count); \ + } while (0) + +/// 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 17b4fde..17f0e94 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -86,6 +86,11 @@ typedef union { } entry; } TSParseActionEntry; +typedef struct { + int32_t start; + int32_t end; +} TSCharacterRange; + struct TSLanguage { uint32_t version; uint32_t symbol_count; @@ -125,6 +130,24 @@ struct TSLanguage { const TSStateId *primary_state_ids; }; +static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { + uint32_t index = 0; + uint32_t size = len - index; + while (size > 1) { + uint32_t half_size = size / 2; + uint32_t mid_index = index + half_size; + TSCharacterRange *range = &ranges[mid_index]; + if (lookahead >= range->start && lookahead <= range->end) { + return true; + } else if (lookahead > range->end) { + index = mid_index; + } + size -= half_size; + } + TSCharacterRange *range = &ranges[index]; + return (lookahead >= range->start && lookahead <= range->end); +} + /* * Lexer Macros */ @@ -154,6 +177,17 @@ struct TSLanguage { goto next_state; \ } +#define ADVANCE_MAP(...) \ + { \ + static const uint16_t map[] = { __VA_ARGS__ }; \ + for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \ + if (map[i] == lookahead) { \ + state = map[i + 1]; \ + goto next_state; \ + } \ + } \ + } + #define SKIP(state_value) \ { \ skip = true; \ @@ -203,14 +237,15 @@ struct TSLanguage { } \ }} -#define REDUCE(symbol_val, child_count_val, ...) \ - {{ \ - .reduce = { \ - .type = TSParseActionTypeReduce, \ - .symbol = symbol_val, \ - .child_count = child_count_val, \ - __VA_ARGS__ \ - }, \ +#define REDUCE(symbol_name, children, precedence, prod_id) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_name, \ + .child_count = children, \ + .dynamic_precedence = precedence, \ + .production_id = prod_id \ + }, \ }} #define RECOVER() \