diff --git a/package/hemar/parser/tree-sitter/src/grammar.json b/package/hemar/parser/tree-sitter/src/grammar.json new file mode 100644 index 0000000..8ca08cb --- /dev/null +++ b/package/hemar/parser/tree-sitter/src/grammar.json @@ -0,0 +1,311 @@ +{ + "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", + "name": "hemar", + "rules": { + "source_file": { + "type": "SEQ", + "members": [ + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "element" + } + } + ] + }, + "element": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "interpolation" + }, + { + "type": "SYMBOL", + "name": "segment" + }, + { + "type": "SYMBOL", + "name": "zalupa" + }, + { + "type": "SYMBOL", + "name": "actual_bracket" + }, + { + "type": "SYMBOL", + "name": "include" + } + ] + }, + "interpolation": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{[" + }, + { + "type": "SYMBOL", + "name": "path" + }, + { + "type": "STRING", + "value": "]}" + } + ] + }, + "segment": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "for" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "element" + } + }, + { + "type": "SYMBOL", + "name": "done" + } + ] + }, + "for": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{[" + }, + { + "type": "STRING", + "value": "for" + }, + { + "type": "SYMBOL", + "name": "string" + }, + { + "type": "STRING", + "value": "in" + }, + { + "type": "SYMBOL", + "name": "path" + }, + { + "type": "STRING", + "value": "]}" + } + ] + }, + "done": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{[" + }, + { + "type": "STRING", + "value": "done" + }, + { + "type": "STRING", + "value": "]}" + } + ] + }, + "actual_bracket": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{[" + }, + { + "type": "STRING", + "value": "{[" + }, + { + "type": "STRING", + "value": "]}" + } + ] + }, + "include": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{[" + }, + { + "type": "STRING", + "value": "include" + }, + { + "type": "SYMBOL", + "name": "path" + }, + { + "type": "STRING", + "value": "]}" + } + ] + }, + "path": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "." + }, + { + "type": "SEQ", + "members": [ + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "string" + }, + { + "type": "SYMBOL", + "name": "index" + } + ] + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "." + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "string" + }, + { + "type": "SYMBOL", + "name": "index" + } + ] + } + ] + } + } + ] + } + ] + }, + "index": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "FIELD", + "name": "value", + "content": { + "type": "SYMBOL", + "name": "integer_index" + } + }, + { + "type": "STRING", + "value": "]" + } + ] + }, + "integer_index": { + "type": "TOKEN", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "\\d" + }, + { + "type": "PATTERN", + "value": "[1-9]\\d*" + }, + { + "type": "PATTERN", + "value": "-[1-9]" + }, + { + "type": "PATTERN", + "value": "-[1-9]\\d*" + } + ] + } + }, + "string": { + "type": "CHOICE", + "members": [ + { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": -1, + "content": { + "type": "PATTERN", + "value": "[^]\\[{} \\n\\t\\r.\\\\\"]+" + } + } + }, + { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": -1, + "content": { + "type": "PATTERN", + "value": "\"([^\"]|\"\")*\"" + } + } + } + ] + }, + "zalupa": { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": -1, + "content": { + "type": "PATTERN", + "value": "(?:\\{[^\\[]|[^{])+" + } + } + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "\\s" + } + ], + "conflicts": [], + "precedences": [], + "externals": [], + "inline": [], + "supertypes": [], + "reserved": {} +} \ No newline at end of file diff --git a/package/hemar/parser/tree-sitter/src/node-types.json b/package/hemar/parser/tree-sitter/src/node-types.json new file mode 100644 index 0000000..f718c5c --- /dev/null +++ b/package/hemar/parser/tree-sitter/src/node-types.json @@ -0,0 +1,215 @@ +[ + { + "type": "actual_bracket", + "named": true, + "fields": {} + }, + { + "type": "done", + "named": true, + "fields": {} + }, + { + "type": "element", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "actual_bracket", + "named": true + }, + { + "type": "include", + "named": true + }, + { + "type": "interpolation", + "named": true + }, + { + "type": "segment", + "named": true + }, + { + "type": "zalupa", + "named": true + } + ] + } + }, + { + "type": "for", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "path", + "named": true + }, + { + "type": "string", + "named": true + } + ] + } + }, + { + "type": "include", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "path", + "named": true + } + ] + } + }, + { + "type": "index", + "named": true, + "fields": { + "value": { + "multiple": false, + "required": true, + "types": [ + { + "type": "integer_index", + "named": true + } + ] + } + } + }, + { + "type": "interpolation", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "path", + "named": true + } + ] + } + }, + { + "type": "path", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "index", + "named": true + }, + { + "type": "string", + "named": true + } + ] + } + }, + { + "type": "segment", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "done", + "named": true + }, + { + "type": "element", + "named": true + }, + { + "type": "for", + "named": true + } + ] + } + }, + { + "type": "source_file", + "named": true, + "root": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "element", + "named": true + } + ] + } + }, + { + "type": "string", + "named": true, + "fields": {} + }, + { + "type": ".", + "named": false + }, + { + "type": "[", + "named": false + }, + { + "type": "]", + "named": false + }, + { + "type": "]}", + "named": false + }, + { + "type": "done", + "named": false + }, + { + "type": "for", + "named": false + }, + { + "type": "in", + "named": false + }, + { + "type": "include", + "named": false + }, + { + "type": "integer_index", + "named": true + }, + { + "type": "zalupa", + "named": true + }, + { + "type": "{[", + "named": false + } +] \ No newline at end of file diff --git a/package/hemar/parser/tree-sitter/src/parser.c b/package/hemar/parser/tree-sitter/src/parser.c new file mode 100644 index 0000000..d6fa4a1 --- /dev/null +++ b/package/hemar/parser/tree-sitter/src/parser.c @@ -0,0 +1,1086 @@ +/* Automatically generated by tree-sitter v0.25.3 */ + +#include "tree_sitter/parser.h" + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#define LANGUAGE_VERSION 15 +#define STATE_COUNT 36 +#define LARGE_STATE_COUNT 2 +#define SYMBOL_COUNT 27 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 14 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 1 +#define MAX_ALIAS_SEQUENCE_LENGTH 6 +#define MAX_RESERVED_WORD_SET_SIZE 0 +#define PRODUCTION_ID_COUNT 2 +#define SUPERTYPE_COUNT 0 + +enum ts_symbol_identifiers { + anon_sym_LBRACE_LBRACK = 1, + anon_sym_RBRACK_RBRACE = 2, + anon_sym_for = 3, + anon_sym_in = 4, + anon_sym_done = 5, + anon_sym_include = 6, + anon_sym_DOT = 7, + anon_sym_LBRACK = 8, + anon_sym_RBRACK = 9, + sym_integer_index = 10, + aux_sym_string_token1 = 11, + aux_sym_string_token2 = 12, + sym_zalupa = 13, + sym_source_file = 14, + sym_element = 15, + sym_interpolation = 16, + sym_segment = 17, + sym_for = 18, + sym_done = 19, + sym_actual_bracket = 20, + sym_include = 21, + sym_path = 22, + sym_index = 23, + sym_string = 24, + aux_sym_source_file_repeat1 = 25, + aux_sym_path_repeat1 = 26, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [anon_sym_LBRACE_LBRACK] = "{[", + [anon_sym_RBRACK_RBRACE] = "]}", + [anon_sym_for] = "for", + [anon_sym_in] = "in", + [anon_sym_done] = "done", + [anon_sym_include] = "include", + [anon_sym_DOT] = ".", + [anon_sym_LBRACK] = "[", + [anon_sym_RBRACK] = "]", + [sym_integer_index] = "integer_index", + [aux_sym_string_token1] = "string_token1", + [aux_sym_string_token2] = "string_token2", + [sym_zalupa] = "zalupa", + [sym_source_file] = "source_file", + [sym_element] = "element", + [sym_interpolation] = "interpolation", + [sym_segment] = "segment", + [sym_for] = "for", + [sym_done] = "done", + [sym_actual_bracket] = "actual_bracket", + [sym_include] = "include", + [sym_path] = "path", + [sym_index] = "index", + [sym_string] = "string", + [aux_sym_source_file_repeat1] = "source_file_repeat1", + [aux_sym_path_repeat1] = "path_repeat1", +}; + +static const TSSymbol ts_symbol_map[] = { + [ts_builtin_sym_end] = ts_builtin_sym_end, + [anon_sym_LBRACE_LBRACK] = anon_sym_LBRACE_LBRACK, + [anon_sym_RBRACK_RBRACE] = anon_sym_RBRACK_RBRACE, + [anon_sym_for] = anon_sym_for, + [anon_sym_in] = anon_sym_in, + [anon_sym_done] = anon_sym_done, + [anon_sym_include] = anon_sym_include, + [anon_sym_DOT] = anon_sym_DOT, + [anon_sym_LBRACK] = anon_sym_LBRACK, + [anon_sym_RBRACK] = anon_sym_RBRACK, + [sym_integer_index] = sym_integer_index, + [aux_sym_string_token1] = aux_sym_string_token1, + [aux_sym_string_token2] = aux_sym_string_token2, + [sym_zalupa] = sym_zalupa, + [sym_source_file] = sym_source_file, + [sym_element] = sym_element, + [sym_interpolation] = sym_interpolation, + [sym_segment] = sym_segment, + [sym_for] = sym_for, + [sym_done] = sym_done, + [sym_actual_bracket] = sym_actual_bracket, + [sym_include] = sym_include, + [sym_path] = sym_path, + [sym_index] = sym_index, + [sym_string] = sym_string, + [aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1, + [aux_sym_path_repeat1] = aux_sym_path_repeat1, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [anon_sym_LBRACE_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACK_RBRACE] = { + .visible = true, + .named = false, + }, + [anon_sym_for] = { + .visible = true, + .named = false, + }, + [anon_sym_in] = { + .visible = true, + .named = false, + }, + [anon_sym_done] = { + .visible = true, + .named = false, + }, + [anon_sym_include] = { + .visible = true, + .named = false, + }, + [anon_sym_DOT] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACK] = { + .visible = true, + .named = false, + }, + [sym_integer_index] = { + .visible = true, + .named = true, + }, + [aux_sym_string_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_string_token2] = { + .visible = false, + .named = false, + }, + [sym_zalupa] = { + .visible = true, + .named = true, + }, + [sym_source_file] = { + .visible = true, + .named = true, + }, + [sym_element] = { + .visible = true, + .named = true, + }, + [sym_interpolation] = { + .visible = true, + .named = true, + }, + [sym_segment] = { + .visible = true, + .named = true, + }, + [sym_for] = { + .visible = true, + .named = true, + }, + [sym_done] = { + .visible = true, + .named = true, + }, + [sym_actual_bracket] = { + .visible = true, + .named = true, + }, + [sym_include] = { + .visible = true, + .named = true, + }, + [sym_path] = { + .visible = true, + .named = true, + }, + [sym_index] = { + .visible = true, + .named = true, + }, + [sym_string] = { + .visible = true, + .named = true, + }, + [aux_sym_source_file_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_path_repeat1] = { + .visible = false, + .named = false, + }, +}; + +enum ts_field_identifiers { + field_value = 1, +}; + +static const char * const ts_field_names[] = { + [0] = NULL, + [field_value] = "value", +}; + +static const TSMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { + [1] = {.index = 0, .length = 1}, +}; + +static const TSFieldMapEntry ts_field_map_entries[] = { + [0] = + {field_value, 1}, +}; + +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 const TSStateId ts_primary_state_ids[STATE_COUNT] = { + [0] = 0, + [1] = 1, + [2] = 2, + [3] = 3, + [4] = 4, + [5] = 5, + [6] = 6, + [7] = 7, + [8] = 8, + [9] = 9, + [10] = 10, + [11] = 11, + [12] = 12, + [13] = 13, + [14] = 14, + [15] = 15, + [16] = 16, + [17] = 17, + [18] = 18, + [19] = 19, + [20] = 20, + [21] = 21, + [22] = 22, + [23] = 23, + [24] = 24, + [25] = 25, + [26] = 26, + [27] = 27, + [28] = 28, + [29] = 29, + [30] = 30, + [31] = 31, + [32] = 32, + [33] = 33, + [34] = 34, + [35] = 35, +}; + +static const TSCharacterRange aux_sym_string_token1_character_set_1[] = { + {0, 0x08}, {0x0b, '\f'}, {0x0e, 0x1f}, {'!', '!'}, {'#', '-'}, {'/', 'Z'}, {'^', 'z'}, {'|', '|'}, + {'~', 0x10ffff}, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(20); + ADVANCE_MAP( + '"', 5, + '-', 17, + '.', 27, + '0', 31, + '[', 28, + ']', 30, + 'd', 14, + 'f', 13, + 'i', 11, + '{', 7, + ); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(0); + if (('1' <= lookahead && lookahead <= '9')) ADVANCE(32); + END_STATE(); + case 1: + ADVANCE_MAP( + '"', 5, + '.', 27, + '[', 28, + 'd', 45, + 'f', 44, + 'i', 42, + '{', 7, + 0x0b, 33, + '\f', 33, + ); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(1); + if (lookahead != 0 && + (lookahead < '[' || ']' < lookahead) && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 2: + if (lookahead == '"') ADVANCE(5); + if (lookahead == '.') ADVANCE(27); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 'f') ADVANCE(44); + if (lookahead == 'i') ADVANCE(42); + if (lookahead == '{') ADVANCE(7); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(34); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(2); + if (lookahead != 0 && + (lookahead < '[' || ']' < lookahead) && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 3: + if (lookahead == '"') ADVANCE(5); + if (lookahead == '.') ADVANCE(27); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(35); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(3); + if (lookahead != 0 && + (lookahead < '[' || ']' < lookahead) && + lookahead != '{' && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 4: + if (lookahead == '"') ADVANCE(5); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(36); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(4); + if (lookahead != 0 && + lookahead != '.' && + (lookahead < '[' || ']' < lookahead) && + lookahead != '{' && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 5: + if (lookahead == '"') ADVANCE(49); + if (lookahead != 0) ADVANCE(5); + END_STATE(); + case 6: + if (lookahead == '.') ADVANCE(27); + if (lookahead == ']') ADVANCE(16); + if (lookahead == 'i') ADVANCE(11); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(6); + END_STATE(); + case 7: + if (lookahead == '[') ADVANCE(21); + END_STATE(); + case 8: + if (lookahead == '[') ADVANCE(21); + if (lookahead != 0) ADVANCE(51); + END_STATE(); + case 9: + if (lookahead == ']') ADVANCE(29); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(9); + END_STATE(); + case 10: + if (lookahead == 'e') ADVANCE(25); + END_STATE(); + case 11: + if (lookahead == 'n') ADVANCE(24); + END_STATE(); + case 12: + if (lookahead == 'n') ADVANCE(10); + END_STATE(); + case 13: + if (lookahead == 'o') ADVANCE(15); + END_STATE(); + case 14: + if (lookahead == 'o') ADVANCE(12); + END_STATE(); + case 15: + if (lookahead == 'r') ADVANCE(23); + END_STATE(); + case 16: + if (lookahead == '}') ADVANCE(22); + END_STATE(); + case 17: + if (('1' <= lookahead && lookahead <= '9')) ADVANCE(32); + END_STATE(); + case 18: + if (lookahead != 0 && + lookahead != '[') ADVANCE(51); + END_STATE(); + case 19: + if (eof) ADVANCE(20); + if (lookahead == '{') ADVANCE(8); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') ADVANCE(50); + if (lookahead != 0) ADVANCE(51); + END_STATE(); + case 20: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 21: + ACCEPT_TOKEN(anon_sym_LBRACE_LBRACK); + END_STATE(); + case 22: + ACCEPT_TOKEN(anon_sym_RBRACK_RBRACE); + END_STATE(); + case 23: + ACCEPT_TOKEN(anon_sym_for); + END_STATE(); + case 24: + ACCEPT_TOKEN(anon_sym_in); + END_STATE(); + case 25: + ACCEPT_TOKEN(anon_sym_done); + END_STATE(); + case 26: + ACCEPT_TOKEN(anon_sym_include); + END_STATE(); + case 27: + ACCEPT_TOKEN(anon_sym_DOT); + END_STATE(); + case 28: + ACCEPT_TOKEN(anon_sym_LBRACK); + END_STATE(); + case 29: + ACCEPT_TOKEN(anon_sym_RBRACK); + END_STATE(); + case 30: + ACCEPT_TOKEN(anon_sym_RBRACK); + if (lookahead == '}') ADVANCE(22); + END_STATE(); + case 31: + ACCEPT_TOKEN(sym_integer_index); + END_STATE(); + case 32: + ACCEPT_TOKEN(sym_integer_index); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(32); + END_STATE(); + case 33: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == '.') ADVANCE(27); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 'd') ADVANCE(45); + if (lookahead == 'f') ADVANCE(44); + if (lookahead == 'i') ADVANCE(42); + if (lookahead == '{') ADVANCE(7); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(33); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(1); + if (lookahead != 0 && + lookahead != '"' && + (lookahead < '[' || ']' < lookahead) && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 34: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == '.') ADVANCE(27); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 'f') ADVANCE(44); + if (lookahead == 'i') ADVANCE(42); + if (lookahead == '{') ADVANCE(7); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(34); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(2); + if (lookahead != 0 && + lookahead != '"' && + (lookahead < '[' || ']' < lookahead) && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 35: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == '.') ADVANCE(27); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(35); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(3); + if (lookahead != 0 && + lookahead != '"' && + (lookahead < '[' || ']' < lookahead) && + lookahead != '{' && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 36: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == '[') ADVANCE(28); + if (lookahead == 0x0b || + lookahead == '\f') ADVANCE(36); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(4); + if (lookahead != 0 && + lookahead != '"' && + lookahead != '.' && + (lookahead < '[' || ']' < lookahead) && + lookahead != '{' && + lookahead != '}') ADVANCE(48); + END_STATE(); + case 37: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'c') ADVANCE(41); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 38: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'd') ADVANCE(40); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 39: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'e') ADVANCE(25); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 40: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'e') ADVANCE(26); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 41: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'l') ADVANCE(47); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 42: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'n') ADVANCE(37); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 43: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'n') ADVANCE(39); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 44: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'o') ADVANCE(46); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 45: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'o') ADVANCE(43); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 46: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'r') ADVANCE(23); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 47: + ACCEPT_TOKEN(aux_sym_string_token1); + if (lookahead == 'u') ADVANCE(38); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 48: + ACCEPT_TOKEN(aux_sym_string_token1); + if ((!eof && set_contains(aux_sym_string_token1_character_set_1, 9, lookahead))) ADVANCE(48); + END_STATE(); + case 49: + ACCEPT_TOKEN(aux_sym_string_token2); + if (lookahead == '"') ADVANCE(5); + END_STATE(); + case 50: + ACCEPT_TOKEN(sym_zalupa); + if (lookahead == '{') ADVANCE(8); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') ADVANCE(50); + if (lookahead != 0) ADVANCE(51); + END_STATE(); + case 51: + ACCEPT_TOKEN(sym_zalupa); + if (lookahead == '{') ADVANCE(18); + if (lookahead != 0) ADVANCE(51); + END_STATE(); + default: + return false; + } +} + +static const TSLexerMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 19}, + [2] = {.lex_state = 1}, + [3] = {.lex_state = 2}, + [4] = {.lex_state = 19}, + [5] = {.lex_state = 19}, + [6] = {.lex_state = 19}, + [7] = {.lex_state = 19}, + [8] = {.lex_state = 3}, + [9] = {.lex_state = 3}, + [10] = {.lex_state = 4}, + [11] = {.lex_state = 19}, + [12] = {.lex_state = 6}, + [13] = {.lex_state = 19}, + [14] = {.lex_state = 19}, + [15] = {.lex_state = 6}, + [16] = {.lex_state = 19}, + [17] = {.lex_state = 19}, + [18] = {.lex_state = 6}, + [19] = {.lex_state = 4}, + [20] = {.lex_state = 19}, + [21] = {.lex_state = 6}, + [22] = {.lex_state = 19}, + [23] = {.lex_state = 6}, + [24] = {.lex_state = 6}, + [25] = {.lex_state = 19}, + [26] = {.lex_state = 0}, + [27] = {.lex_state = 6}, + [28] = {.lex_state = 0}, + [29] = {.lex_state = 6}, + [30] = {.lex_state = 6}, + [31] = {.lex_state = 0}, + [32] = {.lex_state = 6}, + [33] = {.lex_state = 9}, + [34] = {.lex_state = 6}, + [35] = {.lex_state = 6}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [STATE(0)] = { + [ts_builtin_sym_end] = ACTIONS(1), + [anon_sym_LBRACE_LBRACK] = ACTIONS(1), + [anon_sym_RBRACK_RBRACE] = ACTIONS(1), + [anon_sym_for] = ACTIONS(1), + [anon_sym_in] = ACTIONS(1), + [anon_sym_done] = ACTIONS(1), + [anon_sym_DOT] = ACTIONS(1), + [anon_sym_LBRACK] = ACTIONS(1), + [anon_sym_RBRACK] = ACTIONS(1), + [sym_integer_index] = ACTIONS(1), + [aux_sym_string_token2] = ACTIONS(1), + }, + [STATE(1)] = { + [sym_source_file] = STATE(28), + [sym_element] = STATE(5), + [sym_interpolation] = STATE(13), + [sym_segment] = STATE(13), + [sym_for] = STATE(4), + [sym_actual_bracket] = STATE(13), + [sym_include] = STATE(13), + [aux_sym_source_file_repeat1] = STATE(5), + [ts_builtin_sym_end] = ACTIONS(3), + [anon_sym_LBRACE_LBRACK] = ACTIONS(5), + [sym_zalupa] = ACTIONS(7), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 9, + ACTIONS(9), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(11), 1, + anon_sym_for, + ACTIONS(13), 1, + anon_sym_done, + ACTIONS(15), 1, + anon_sym_include, + ACTIONS(17), 1, + anon_sym_DOT, + ACTIONS(19), 1, + anon_sym_LBRACK, + STATE(27), 1, + sym_path, + ACTIONS(21), 2, + aux_sym_string_token1, + aux_sym_string_token2, + STATE(15), 2, + sym_index, + sym_string, + [30] = 8, + ACTIONS(9), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(11), 1, + anon_sym_for, + ACTIONS(15), 1, + anon_sym_include, + ACTIONS(17), 1, + anon_sym_DOT, + ACTIONS(19), 1, + anon_sym_LBRACK, + STATE(27), 1, + sym_path, + ACTIONS(21), 2, + aux_sym_string_token1, + aux_sym_string_token2, + STATE(15), 2, + sym_index, + sym_string, + [57] = 6, + ACTIONS(7), 1, + sym_zalupa, + ACTIONS(23), 1, + anon_sym_LBRACE_LBRACK, + STATE(4), 1, + sym_for, + STATE(14), 1, + sym_done, + STATE(6), 2, + sym_element, + aux_sym_source_file_repeat1, + STATE(13), 4, + sym_interpolation, + sym_segment, + sym_actual_bracket, + sym_include, + [80] = 6, + ACTIONS(5), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(7), 1, + sym_zalupa, + ACTIONS(25), 1, + ts_builtin_sym_end, + STATE(4), 1, + sym_for, + STATE(7), 2, + sym_element, + aux_sym_source_file_repeat1, + STATE(13), 4, + sym_interpolation, + sym_segment, + sym_actual_bracket, + sym_include, + [103] = 6, + ACTIONS(7), 1, + sym_zalupa, + ACTIONS(23), 1, + anon_sym_LBRACE_LBRACK, + STATE(4), 1, + sym_for, + STATE(20), 1, + sym_done, + STATE(7), 2, + sym_element, + aux_sym_source_file_repeat1, + STATE(13), 4, + sym_interpolation, + sym_segment, + sym_actual_bracket, + sym_include, + [126] = 6, + ACTIONS(27), 1, + ts_builtin_sym_end, + ACTIONS(29), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(32), 1, + sym_zalupa, + STATE(4), 1, + sym_for, + STATE(7), 2, + sym_element, + aux_sym_source_file_repeat1, + STATE(13), 4, + sym_interpolation, + sym_segment, + sym_actual_bracket, + sym_include, + [149] = 5, + ACTIONS(17), 1, + anon_sym_DOT, + ACTIONS(19), 1, + anon_sym_LBRACK, + STATE(35), 1, + sym_path, + ACTIONS(21), 2, + aux_sym_string_token1, + aux_sym_string_token2, + STATE(15), 2, + sym_index, + sym_string, + [167] = 5, + ACTIONS(17), 1, + anon_sym_DOT, + ACTIONS(19), 1, + anon_sym_LBRACK, + STATE(32), 1, + sym_path, + ACTIONS(21), 2, + aux_sym_string_token1, + aux_sym_string_token2, + STATE(15), 2, + sym_index, + sym_string, + [185] = 3, + ACTIONS(19), 1, + anon_sym_LBRACK, + ACTIONS(21), 2, + aux_sym_string_token1, + aux_sym_string_token2, + STATE(23), 2, + sym_index, + sym_string, + [197] = 2, + ACTIONS(37), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(35), 2, + ts_builtin_sym_end, + sym_zalupa, + [205] = 1, + ACTIONS(39), 3, + anon_sym_RBRACK_RBRACE, + anon_sym_in, + anon_sym_DOT, + [211] = 2, + ACTIONS(43), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(41), 2, + ts_builtin_sym_end, + sym_zalupa, + [219] = 2, + ACTIONS(47), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(45), 2, + ts_builtin_sym_end, + sym_zalupa, + [227] = 3, + ACTIONS(49), 1, + anon_sym_RBRACK_RBRACE, + ACTIONS(51), 1, + anon_sym_DOT, + STATE(18), 1, + aux_sym_path_repeat1, + [237] = 2, + ACTIONS(55), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(53), 2, + ts_builtin_sym_end, + sym_zalupa, + [245] = 2, + ACTIONS(59), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(57), 2, + ts_builtin_sym_end, + sym_zalupa, + [253] = 3, + ACTIONS(51), 1, + anon_sym_DOT, + ACTIONS(61), 1, + anon_sym_RBRACK_RBRACE, + STATE(21), 1, + aux_sym_path_repeat1, + [263] = 3, + ACTIONS(21), 1, + aux_sym_string_token2, + ACTIONS(63), 1, + aux_sym_string_token1, + STATE(31), 1, + sym_string, + [273] = 2, + ACTIONS(67), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(65), 2, + ts_builtin_sym_end, + sym_zalupa, + [281] = 3, + ACTIONS(69), 1, + anon_sym_RBRACK_RBRACE, + ACTIONS(71), 1, + anon_sym_DOT, + STATE(21), 1, + aux_sym_path_repeat1, + [291] = 2, + ACTIONS(76), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(74), 2, + ts_builtin_sym_end, + sym_zalupa, + [299] = 1, + ACTIONS(69), 2, + anon_sym_RBRACK_RBRACE, + anon_sym_DOT, + [304] = 1, + ACTIONS(78), 2, + anon_sym_RBRACK_RBRACE, + anon_sym_DOT, + [309] = 2, + ACTIONS(80), 1, + anon_sym_LBRACE_LBRACK, + ACTIONS(82), 1, + sym_zalupa, + [316] = 1, + ACTIONS(84), 1, + sym_integer_index, + [320] = 1, + ACTIONS(86), 1, + anon_sym_RBRACK_RBRACE, + [324] = 1, + ACTIONS(88), 1, + ts_builtin_sym_end, + [328] = 1, + ACTIONS(90), 1, + anon_sym_RBRACK_RBRACE, + [332] = 1, + ACTIONS(49), 1, + anon_sym_RBRACK_RBRACE, + [336] = 1, + ACTIONS(92), 1, + anon_sym_in, + [340] = 1, + ACTIONS(94), 1, + anon_sym_RBRACK_RBRACE, + [344] = 1, + ACTIONS(96), 1, + anon_sym_RBRACK, + [348] = 1, + ACTIONS(98), 1, + anon_sym_RBRACK_RBRACE, + [352] = 1, + ACTIONS(100), 1, + anon_sym_RBRACK_RBRACE, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(2)] = 0, + [SMALL_STATE(3)] = 30, + [SMALL_STATE(4)] = 57, + [SMALL_STATE(5)] = 80, + [SMALL_STATE(6)] = 103, + [SMALL_STATE(7)] = 126, + [SMALL_STATE(8)] = 149, + [SMALL_STATE(9)] = 167, + [SMALL_STATE(10)] = 185, + [SMALL_STATE(11)] = 197, + [SMALL_STATE(12)] = 205, + [SMALL_STATE(13)] = 211, + [SMALL_STATE(14)] = 219, + [SMALL_STATE(15)] = 227, + [SMALL_STATE(16)] = 237, + [SMALL_STATE(17)] = 245, + [SMALL_STATE(18)] = 253, + [SMALL_STATE(19)] = 263, + [SMALL_STATE(20)] = 273, + [SMALL_STATE(21)] = 281, + [SMALL_STATE(22)] = 291, + [SMALL_STATE(23)] = 299, + [SMALL_STATE(24)] = 304, + [SMALL_STATE(25)] = 309, + [SMALL_STATE(26)] = 316, + [SMALL_STATE(27)] = 320, + [SMALL_STATE(28)] = 324, + [SMALL_STATE(29)] = 328, + [SMALL_STATE(30)] = 332, + [SMALL_STATE(31)] = 336, + [SMALL_STATE(32)] = 340, + [SMALL_STATE(33)] = 344, + [SMALL_STATE(34)] = 348, + [SMALL_STATE(35)] = 352, +}; + +static const TSParseActionEntry ts_parse_actions[] = { + [0] = {.entry = {.count = 0, .reusable = false}}, + [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), + [3] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 0, 0, 0), + [5] = {.entry = {.count = 1, .reusable = false}}, SHIFT(3), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [9] = {.entry = {.count = 1, .reusable = false}}, SHIFT(29), + [11] = {.entry = {.count = 1, .reusable = false}}, SHIFT(19), + [13] = {.entry = {.count = 1, .reusable = false}}, SHIFT(34), + [15] = {.entry = {.count = 1, .reusable = false}}, SHIFT(9), + [17] = {.entry = {.count = 1, .reusable = false}}, SHIFT(30), + [19] = {.entry = {.count = 1, .reusable = false}}, SHIFT(26), + [21] = {.entry = {.count = 1, .reusable = false}}, SHIFT(12), + [23] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2), + [25] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0), + [27] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), + [29] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(3), + [32] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(13), + [35] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_actual_bracket, 3, 0, 0), + [37] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_actual_bracket, 3, 0, 0), + [39] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 1, 0, 0), + [41] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_element, 1, 0, 0), + [43] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_element, 1, 0, 0), + [45] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_segment, 2, 0, 0), + [47] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_segment, 2, 0, 0), + [49] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_path, 1, 0, 0), + [51] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), + [53] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_done, 3, 0, 0), + [55] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_done, 3, 0, 0), + [57] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_interpolation, 3, 0, 0), + [59] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_interpolation, 3, 0, 0), + [61] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_path, 2, 0, 0), + [63] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [65] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_segment, 3, 0, 0), + [67] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_segment, 3, 0, 0), + [69] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_path_repeat1, 2, 0, 0), + [71] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_path_repeat1, 2, 0, 0), SHIFT_REPEAT(10), + [74] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_include, 4, 0, 0), + [76] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_include, 4, 0, 0), + [78] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_index, 3, 0, 1), + [80] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_for, 6, 0, 0), + [82] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_for, 6, 0, 0), + [84] = {.entry = {.count = 1, .reusable = true}}, SHIFT(33), + [86] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), + [88] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [90] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [92] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), + [94] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), + [96] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), + [98] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), + [100] = {.entry = {.count = 1, .reusable = true}}, SHIFT(25), +}; + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef TREE_SITTER_HIDE_SYMBOLS +#define TS_PUBLIC +#elif defined(_WIN32) +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) +#endif + +TS_PUBLIC const TSLanguage *tree_sitter_hemar(void) { + static const TSLanguage language = { + .abi_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, + .supertype_count = SUPERTYPE_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, + .field_names = ts_field_names, + .field_map_slices = ts_field_map_slices, + .field_map_entries = ts_field_map_entries, + .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 = (const void*)ts_lex_modes, + .lex_fn = ts_lex, + .primary_state_ids = ts_primary_state_ids, + .name = "hemar", + .max_reserved_word_set_size = 0, + .metadata = { + .major_version = 0, + .minor_version = 1, + .patch_version = 0, + }, + }; + return &language; +} +#ifdef __cplusplus +} +#endif diff --git a/package/hemar/parser/tree-sitter/src/tree_sitter/alloc.h b/package/hemar/parser/tree-sitter/src/tree_sitter/alloc.h new file mode 100644 index 0000000..1abdd12 --- /dev/null +++ b/package/hemar/parser/tree-sitter/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 size); +extern void *(*ts_current_calloc)(size_t count, size_t size); +extern void *(*ts_current_realloc)(void *ptr, size_t size); +extern void (*ts_current_free)(void *ptr); + +#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/package/hemar/parser/tree-sitter/src/tree_sitter/array.h b/package/hemar/parser/tree-sitter/src/tree_sitter/array.h new file mode 100644 index 0000000..a17a574 --- /dev/null +++ b/package/hemar/parser/tree-sitter/src/tree_sitter/array.h @@ -0,0 +1,291 @@ +#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(push) +#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(pop) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ARRAY_H_ diff --git a/package/hemar/parser/tree-sitter/src/tree_sitter/parser.h b/package/hemar/parser/tree-sitter/src/tree_sitter/parser.h new file mode 100644 index 0000000..cdbe64c --- /dev/null +++ b/package/hemar/parser/tree-sitter/src/tree_sitter/parser.h @@ -0,0 +1,287 @@ +#ifndef TREE_SITTER_PARSER_H_ +#define TREE_SITTER_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define ts_builtin_sym_error ((TSSymbol)-1) +#define ts_builtin_sym_end 0 +#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 + +#ifndef TREE_SITTER_API_H_ +typedef uint16_t TSStateId; +typedef uint16_t TSSymbol; +typedef uint16_t TSFieldId; +typedef struct TSLanguage TSLanguage; +typedef struct TSLanguageMetadata TSLanguageMetadata; +typedef struct TSLanguageMetadata { + uint8_t major_version; + uint8_t minor_version; + uint8_t patch_version; +} TSLanguageMetadata; +#endif + +typedef struct { + TSFieldId field_id; + uint8_t child_index; + bool inherited; +} TSFieldMapEntry; + +// Used to index the field and supertype maps. +typedef struct { + uint16_t index; + uint16_t length; +} TSMapSlice; + +typedef struct { + bool visible; + bool named; + bool supertype; +} TSSymbolMetadata; + +typedef struct TSLexer TSLexer; + +struct TSLexer { + int32_t lookahead; + TSSymbol result_symbol; + void (*advance)(TSLexer *, bool); + void (*mark_end)(TSLexer *); + uint32_t (*get_column)(TSLexer *); + bool (*is_at_included_range_start)(const TSLexer *); + bool (*eof)(const TSLexer *); + void (*log)(const TSLexer *, const char *, ...); +}; + +typedef enum { + TSParseActionTypeShift, + TSParseActionTypeReduce, + TSParseActionTypeAccept, + TSParseActionTypeRecover, +} TSParseActionType; + +typedef union { + struct { + uint8_t type; + TSStateId state; + bool extra; + bool repetition; + } shift; + struct { + uint8_t type; + uint8_t child_count; + TSSymbol symbol; + int16_t dynamic_precedence; + uint16_t production_id; + } reduce; + uint8_t type; +} TSParseAction; + +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; +} TSLexMode; + +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; + uint16_t reserved_word_set_id; +} TSLexerMode; + +typedef union { + TSParseAction action; + struct { + uint8_t count; + bool reusable; + } entry; +} TSParseActionEntry; + +typedef struct { + int32_t start; + int32_t end; +} TSCharacterRange; + +struct TSLanguage { + uint32_t abi_version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + uint32_t state_count; + uint32_t large_state_count; + uint32_t production_id_count; + uint32_t field_count; + uint16_t max_alias_sequence_length; + const uint16_t *parse_table; + const uint16_t *small_parse_table; + const uint32_t *small_parse_table_map; + const TSParseActionEntry *parse_actions; + const char * const *symbol_names; + const char * const *field_names; + const TSMapSlice *field_map_slices; + const TSFieldMapEntry *field_map_entries; + const TSSymbolMetadata *symbol_metadata; + const TSSymbol *public_symbol_map; + const uint16_t *alias_map; + const TSSymbol *alias_sequences; + const TSLexerMode *lex_modes; + bool (*lex_fn)(TSLexer *, TSStateId); + bool (*keyword_lex_fn)(TSLexer *, TSStateId); + TSSymbol keyword_capture_token; + struct { + const bool *states; + const TSSymbol *symbol_map; + void *(*create)(void); + void (*destroy)(void *); + bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); + unsigned (*serialize)(void *, char *); + void (*deserialize)(void *, const char *, unsigned); + } external_scanner; + const TSStateId *primary_state_ids; + const char *name; + const TSSymbol *reserved_words; + uint16_t max_reserved_word_set_size; + uint32_t supertype_count; + const TSSymbol *supertype_symbols; + const TSMapSlice *supertype_map_slices; + const TSSymbol *supertype_map_entries; + TSLanguageMetadata metadata; +}; + +static inline bool set_contains(const 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; + const 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; + } + const TSCharacterRange *range = &ranges[index]; + return (lookahead >= range->start && lookahead <= range->end); +} + +/* + * 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; \ + next_state: \ + lexer->advance(lexer, skip); \ + start: \ + skip = false; \ + lookahead = lexer->lookahead; + +#define ADVANCE(state_value) \ + { \ + state = state_value; \ + 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; \ + state = state_value; \ + goto next_state; \ + } + +#define ACCEPT_TOKEN(symbol_value) \ + result = true; \ + lexer->result_symbol = symbol_value; \ + lexer->mark_end(lexer); + +#define END_STATE() return result; + +/* + * Parse Table Macros + */ + +#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) + +#define STATE(id) id + +#define ACTIONS(id) id + +#define SHIFT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = (state_value) \ + } \ + }} + +#define SHIFT_REPEAT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = (state_value), \ + .repetition = true \ + } \ + }} + +#define SHIFT_EXTRA() \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .extra = true \ + } \ + }} + +#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() \ + {{ \ + .type = TSParseActionTypeRecover \ + }} + +#define ACCEPT_INPUT() \ + {{ \ + .type = TSParseActionTypeAccept \ + }} + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_