diff --git a/grammar.js b/grammar.js index 92fca6a..d9a555e 100644 --- a/grammar.js +++ b/grammar.js @@ -11,7 +11,69 @@ module.exports = grammar({ name: "vvk", rules: { - // TODO: add the actual grammar rules - source_file: $ => "hello" + source_file: $ => repeat($._statement), + + _statement: $ => choice($.mod_statement, $._directive_statement), + _directive_statement: $ => seq( + repeat($.directive), + choice($.assign_statement, $.expression) + ), + mod_statement: $ => seq('mod', $.identifier, ';'), + assign_statement: $ => seq($.identifier, '=', $.expression), + + expression: $ => choice( + $.item_path, + $.string_literal, + $.array, + $.target, + ), + _item_path: $ => prec.left(repeat1(seq('::', $.identifier))), + item_path: $ => $._item_path, + relative_item_path: $ => seq($.identifier, optional($._item_path)), + array: $ => seq( + '[', + optional(seq( + $.expression, + repeat(seq(',', $.expression)), + optional(','), + )), + ']' + ), + target: $ => seq( + $.identifier, + $._arguments, + ), + + argument: $ => seq( + $.identifier, + ':', + $.expression + ), + _arguments: $ => seq( + '{', + optional(seq( + $.argument, + repeat(seq(',', $.argument)), + optional(','), + )), + '}' + ), + + string_literal: $ => seq( + '\'', + repeat(choice( + alias(token.immediate(prec(1, /[^\\'\n]+/)), $.string_content), + $.escape_sequence, + )), + '\'' + ), + + escape_sequence: _ => token(prec(1, seq( + '\\', + /./, + ))), + + identifier: $ => /[a-zA-Z][a-zA-Z0-9_-]*/, + directive: $ => /@[a-z]+/, } }); diff --git a/src/grammar.json b/src/grammar.json new file mode 100644 index 0000000..ec97253 --- /dev/null +++ b/src/grammar.json @@ -0,0 +1,378 @@ +{ + "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", + "name": "vvk", + "rules": { + "source_file": { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "_statement" + } + }, + "_statement": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "mod_statement" + }, + { + "type": "SYMBOL", + "name": "_directive_statement" + } + ] + }, + "_directive_statement": { + "type": "SEQ", + "members": [ + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "directive" + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "assign_statement" + }, + { + "type": "SYMBOL", + "name": "expression" + } + ] + } + ] + }, + "mod_statement": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "mod" + }, + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "assign_statement": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "STRING", + "value": "=" + }, + { + "type": "SYMBOL", + "name": "expression" + } + ] + }, + "expression": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "item_path" + }, + { + "type": "SYMBOL", + "name": "string_literal" + }, + { + "type": "SYMBOL", + "name": "array" + }, + { + "type": "SYMBOL", + "name": "target" + } + ] + }, + "_item_path": { + "type": "PREC_LEFT", + "value": 0, + "content": { + "type": "REPEAT1", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "::" + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + } + } + }, + "item_path": { + "type": "SYMBOL", + "name": "_item_path" + }, + "relative_item_path": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_item_path" + }, + { + "type": "BLANK" + } + ] + } + ] + }, + "array": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "expression" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "expression" + } + ] + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "BLANK" + } + ] + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "]" + } + ] + }, + "target": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "SYMBOL", + "name": "_arguments" + } + ] + }, + "argument": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "STRING", + "value": ":" + }, + { + "type": "SYMBOL", + "name": "expression" + } + ] + }, + "_arguments": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "argument" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "argument" + } + ] + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "BLANK" + } + ] + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "}" + } + ] + }, + "string_literal": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "'" + }, + { + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "ALIAS", + "content": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "PREC", + "value": 1, + "content": { + "type": "PATTERN", + "value": "[^\\\\'\\n]+" + } + } + }, + "named": true, + "value": "string_content" + }, + { + "type": "SYMBOL", + "name": "escape_sequence" + } + ] + } + }, + { + "type": "STRING", + "value": "'" + } + ] + }, + "escape_sequence": { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": 1, + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "\\" + }, + { + "type": "PATTERN", + "value": "." + } + ] + } + } + }, + "identifier": { + "type": "PATTERN", + "value": "[a-zA-Z][a-zA-Z0-9_-]*" + }, + "directive": { + "type": "PATTERN", + "value": "@[a-z]+" + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "\\s" + } + ], + "conflicts": [], + "precedences": [], + "externals": [], + "inline": [], + "supertypes": [], + "reserved": {} +} \ No newline at end of file diff --git a/src/node-types.json b/src/node-types.json new file mode 100644 index 0000000..ea5ff28 --- /dev/null +++ b/src/node-types.json @@ -0,0 +1,238 @@ +[ + { + "type": "argument", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "expression", + "named": true + }, + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "array", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "expression", + "named": true + } + ] + } + }, + { + "type": "assign_statement", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "expression", + "named": true + }, + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "expression", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "array", + "named": true + }, + { + "type": "item_path", + "named": true + }, + { + "type": "string_literal", + "named": true + }, + { + "type": "target", + "named": true + } + ] + } + }, + { + "type": "item_path", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "mod_statement", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "source_file", + "named": true, + "root": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "assign_statement", + "named": true + }, + { + "type": "directive", + "named": true + }, + { + "type": "expression", + "named": true + }, + { + "type": "mod_statement", + "named": true + } + ] + } + }, + { + "type": "string_literal", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "escape_sequence", + "named": true + }, + { + "type": "string_content", + "named": true + } + ] + } + }, + { + "type": "target", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "argument", + "named": true + }, + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "'", + "named": false + }, + { + "type": ",", + "named": false + }, + { + "type": ":", + "named": false + }, + { + "type": "::", + "named": false + }, + { + "type": ";", + "named": false + }, + { + "type": "=", + "named": false + }, + { + "type": "[", + "named": false + }, + { + "type": "]", + "named": false + }, + { + "type": "directive", + "named": true + }, + { + "type": "escape_sequence", + "named": true + }, + { + "type": "identifier", + "named": true + }, + { + "type": "mod", + "named": false + }, + { + "type": "string_content", + "named": true + }, + { + "type": "{", + "named": false + }, + { + "type": "}", + "named": false + } +] \ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..b926988 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,1389 @@ +/* Automatically @generated by tree-sitter v0.25.10 */ + +#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 54 +#define LARGE_STATE_COUNT 4 +#define SYMBOL_COUNT 35 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 16 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 0 +#define MAX_ALIAS_SEQUENCE_LENGTH 5 +#define MAX_RESERVED_WORD_SET_SIZE 0 +#define PRODUCTION_ID_COUNT 1 +#define SUPERTYPE_COUNT 0 + +enum ts_symbol_identifiers { + anon_sym_mod = 1, + anon_sym_SEMI = 2, + anon_sym_EQ = 3, + anon_sym_COLON_COLON = 4, + anon_sym_LBRACK = 5, + anon_sym_COMMA = 6, + anon_sym_RBRACK = 7, + anon_sym_COLON = 8, + anon_sym_LBRACE = 9, + anon_sym_RBRACE = 10, + anon_sym_SQUOTE = 11, + aux_sym_string_literal_token1 = 12, + sym_escape_sequence = 13, + sym_identifier = 14, + sym_directive = 15, + sym_source_file = 16, + sym__statement = 17, + sym__directive_statement = 18, + sym_mod_statement = 19, + sym_assign_statement = 20, + sym_expression = 21, + sym__item_path = 22, + sym_item_path = 23, + sym_array = 24, + sym_target = 25, + sym_argument = 26, + sym__arguments = 27, + sym_string_literal = 28, + aux_sym_source_file_repeat1 = 29, + aux_sym__directive_statement_repeat1 = 30, + aux_sym__item_path_repeat1 = 31, + aux_sym_array_repeat1 = 32, + aux_sym__arguments_repeat1 = 33, + aux_sym_string_literal_repeat1 = 34, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [anon_sym_mod] = "mod", + [anon_sym_SEMI] = ";", + [anon_sym_EQ] = "=", + [anon_sym_COLON_COLON] = "::", + [anon_sym_LBRACK] = "[", + [anon_sym_COMMA] = ",", + [anon_sym_RBRACK] = "]", + [anon_sym_COLON] = ":", + [anon_sym_LBRACE] = "{", + [anon_sym_RBRACE] = "}", + [anon_sym_SQUOTE] = "'", + [aux_sym_string_literal_token1] = "string_content", + [sym_escape_sequence] = "escape_sequence", + [sym_identifier] = "identifier", + [sym_directive] = "directive", + [sym_source_file] = "source_file", + [sym__statement] = "_statement", + [sym__directive_statement] = "_directive_statement", + [sym_mod_statement] = "mod_statement", + [sym_assign_statement] = "assign_statement", + [sym_expression] = "expression", + [sym__item_path] = "_item_path", + [sym_item_path] = "item_path", + [sym_array] = "array", + [sym_target] = "target", + [sym_argument] = "argument", + [sym__arguments] = "_arguments", + [sym_string_literal] = "string_literal", + [aux_sym_source_file_repeat1] = "source_file_repeat1", + [aux_sym__directive_statement_repeat1] = "_directive_statement_repeat1", + [aux_sym__item_path_repeat1] = "_item_path_repeat1", + [aux_sym_array_repeat1] = "array_repeat1", + [aux_sym__arguments_repeat1] = "_arguments_repeat1", + [aux_sym_string_literal_repeat1] = "string_literal_repeat1", +}; + +static const TSSymbol ts_symbol_map[] = { + [ts_builtin_sym_end] = ts_builtin_sym_end, + [anon_sym_mod] = anon_sym_mod, + [anon_sym_SEMI] = anon_sym_SEMI, + [anon_sym_EQ] = anon_sym_EQ, + [anon_sym_COLON_COLON] = anon_sym_COLON_COLON, + [anon_sym_LBRACK] = anon_sym_LBRACK, + [anon_sym_COMMA] = anon_sym_COMMA, + [anon_sym_RBRACK] = anon_sym_RBRACK, + [anon_sym_COLON] = anon_sym_COLON, + [anon_sym_LBRACE] = anon_sym_LBRACE, + [anon_sym_RBRACE] = anon_sym_RBRACE, + [anon_sym_SQUOTE] = anon_sym_SQUOTE, + [aux_sym_string_literal_token1] = aux_sym_string_literal_token1, + [sym_escape_sequence] = sym_escape_sequence, + [sym_identifier] = sym_identifier, + [sym_directive] = sym_directive, + [sym_source_file] = sym_source_file, + [sym__statement] = sym__statement, + [sym__directive_statement] = sym__directive_statement, + [sym_mod_statement] = sym_mod_statement, + [sym_assign_statement] = sym_assign_statement, + [sym_expression] = sym_expression, + [sym__item_path] = sym__item_path, + [sym_item_path] = sym_item_path, + [sym_array] = sym_array, + [sym_target] = sym_target, + [sym_argument] = sym_argument, + [sym__arguments] = sym__arguments, + [sym_string_literal] = sym_string_literal, + [aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1, + [aux_sym__directive_statement_repeat1] = aux_sym__directive_statement_repeat1, + [aux_sym__item_path_repeat1] = aux_sym__item_path_repeat1, + [aux_sym_array_repeat1] = aux_sym_array_repeat1, + [aux_sym__arguments_repeat1] = aux_sym__arguments_repeat1, + [aux_sym_string_literal_repeat1] = aux_sym_string_literal_repeat1, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [anon_sym_mod] = { + .visible = true, + .named = false, + }, + [anon_sym_SEMI] = { + .visible = true, + .named = false, + }, + [anon_sym_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_COLON_COLON] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_COMMA] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_COLON] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACE] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACE] = { + .visible = true, + .named = false, + }, + [anon_sym_SQUOTE] = { + .visible = true, + .named = false, + }, + [aux_sym_string_literal_token1] = { + .visible = true, + .named = true, + }, + [sym_escape_sequence] = { + .visible = true, + .named = true, + }, + [sym_identifier] = { + .visible = true, + .named = true, + }, + [sym_directive] = { + .visible = true, + .named = true, + }, + [sym_source_file] = { + .visible = true, + .named = true, + }, + [sym__statement] = { + .visible = false, + .named = true, + }, + [sym__directive_statement] = { + .visible = false, + .named = true, + }, + [sym_mod_statement] = { + .visible = true, + .named = true, + }, + [sym_assign_statement] = { + .visible = true, + .named = true, + }, + [sym_expression] = { + .visible = true, + .named = true, + }, + [sym__item_path] = { + .visible = false, + .named = true, + }, + [sym_item_path] = { + .visible = true, + .named = true, + }, + [sym_array] = { + .visible = true, + .named = true, + }, + [sym_target] = { + .visible = true, + .named = true, + }, + [sym_argument] = { + .visible = true, + .named = true, + }, + [sym__arguments] = { + .visible = false, + .named = true, + }, + [sym_string_literal] = { + .visible = true, + .named = true, + }, + [aux_sym_source_file_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym__directive_statement_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym__item_path_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_array_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym__arguments_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_string_literal_repeat1] = { + .visible = false, + .named = false, + }, +}; + +static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { + [0] = {0}, +}; + +static const uint16_t ts_non_terminal_alias_map[] = { + 0, +}; + +static 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, + [36] = 36, + [37] = 37, + [38] = 38, + [39] = 39, + [40] = 40, + [41] = 41, + [42] = 42, + [43] = 43, + [44] = 44, + [45] = 45, + [46] = 46, + [47] = 47, + [48] = 48, + [49] = 49, + [50] = 50, + [51] = 51, + [52] = 52, + [53] = 53, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(8); + ADVANCE_MAP( + '\'', 19, + ',', 14, + ':', 16, + ';', 10, + '=', 11, + '@', 5, + '[', 13, + '\\', 6, + ']', 15, + 'm', 24, + '{', 17, + '}', 18, + ); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(0); + if (('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 1: + if (lookahead == '\n') SKIP(3); + if (lookahead == '\'') ADVANCE(19); + if (lookahead == '\\') ADVANCE(6); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') ADVANCE(20); + if (lookahead != 0) ADVANCE(21); + END_STATE(); + case 2: + if (lookahead == '\'') ADVANCE(19); + if (lookahead == ':') ADVANCE(4); + if (lookahead == '@') ADVANCE(5); + if (lookahead == '[') ADVANCE(13); + if (lookahead == ']') ADVANCE(15); + if (lookahead == '}') ADVANCE(18); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(2); + if (('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 3: + if (lookahead == '\'') ADVANCE(19); + if (lookahead == '\\') ADVANCE(6); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(3); + END_STATE(); + case 4: + if (lookahead == ':') ADVANCE(12); + END_STATE(); + case 5: + if (('a' <= lookahead && lookahead <= 'z')) ADVANCE(26); + END_STATE(); + case 6: + if (lookahead != 0 && + lookahead != '\n') ADVANCE(22); + END_STATE(); + case 7: + if (eof) ADVANCE(8); + ADVANCE_MAP( + '\'', 19, + ',', 14, + ':', 4, + '@', 5, + '[', 13, + ']', 15, + 'm', 24, + '}', 18, + ); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(7); + if (('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 8: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 9: + ACCEPT_TOKEN(anon_sym_mod); + if (lookahead == '-' || + ('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 10: + ACCEPT_TOKEN(anon_sym_SEMI); + END_STATE(); + case 11: + ACCEPT_TOKEN(anon_sym_EQ); + END_STATE(); + case 12: + ACCEPT_TOKEN(anon_sym_COLON_COLON); + END_STATE(); + case 13: + ACCEPT_TOKEN(anon_sym_LBRACK); + END_STATE(); + case 14: + ACCEPT_TOKEN(anon_sym_COMMA); + END_STATE(); + case 15: + ACCEPT_TOKEN(anon_sym_RBRACK); + END_STATE(); + case 16: + ACCEPT_TOKEN(anon_sym_COLON); + END_STATE(); + case 17: + ACCEPT_TOKEN(anon_sym_LBRACE); + END_STATE(); + case 18: + ACCEPT_TOKEN(anon_sym_RBRACE); + END_STATE(); + case 19: + ACCEPT_TOKEN(anon_sym_SQUOTE); + END_STATE(); + case 20: + ACCEPT_TOKEN(aux_sym_string_literal_token1); + if (lookahead == '\t' || + (0x0b <= lookahead && lookahead <= '\r') || + lookahead == ' ') ADVANCE(20); + if (lookahead != 0 && + (lookahead < '\t' || '\r' < lookahead) && + lookahead != '\'' && + lookahead != '\\') ADVANCE(21); + END_STATE(); + case 21: + ACCEPT_TOKEN(aux_sym_string_literal_token1); + if (lookahead != 0 && + lookahead != '\n' && + lookahead != '\'' && + lookahead != '\\') ADVANCE(21); + END_STATE(); + case 22: + ACCEPT_TOKEN(sym_escape_sequence); + END_STATE(); + case 23: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'd') ADVANCE(9); + if (lookahead == '-' || + ('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 24: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(23); + if (lookahead == '-' || + ('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 25: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == '-' || + ('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(25); + END_STATE(); + case 26: + ACCEPT_TOKEN(sym_directive); + if (('a' <= lookahead && lookahead <= 'z')) ADVANCE(26); + END_STATE(); + default: + return false; + } +} + +static const TSLexerMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 7}, + [2] = {.lex_state = 7}, + [3] = {.lex_state = 7}, + [4] = {.lex_state = 2}, + [5] = {.lex_state = 2}, + [6] = {.lex_state = 2}, + [7] = {.lex_state = 2}, + [8] = {.lex_state = 7}, + [9] = {.lex_state = 2}, + [10] = {.lex_state = 2}, + [11] = {.lex_state = 2}, + [12] = {.lex_state = 7}, + [13] = {.lex_state = 7}, + [14] = {.lex_state = 7}, + [15] = {.lex_state = 7}, + [16] = {.lex_state = 7}, + [17] = {.lex_state = 7}, + [18] = {.lex_state = 7}, + [19] = {.lex_state = 7}, + [20] = {.lex_state = 7}, + [21] = {.lex_state = 7}, + [22] = {.lex_state = 7}, + [23] = {.lex_state = 7}, + [24] = {.lex_state = 7}, + [25] = {.lex_state = 7}, + [26] = {.lex_state = 7}, + [27] = {.lex_state = 7}, + [28] = {.lex_state = 7}, + [29] = {.lex_state = 2}, + [30] = {.lex_state = 7}, + [31] = {.lex_state = 1}, + [32] = {.lex_state = 1}, + [33] = {.lex_state = 1}, + [34] = {.lex_state = 0}, + [35] = {.lex_state = 0}, + [36] = {.lex_state = 2}, + [37] = {.lex_state = 0}, + [38] = {.lex_state = 0}, + [39] = {.lex_state = 0}, + [40] = {.lex_state = 2}, + [41] = {.lex_state = 2}, + [42] = {.lex_state = 0}, + [43] = {.lex_state = 0}, + [44] = {.lex_state = 0}, + [45] = {.lex_state = 0}, + [46] = {.lex_state = 0}, + [47] = {.lex_state = 0}, + [48] = {.lex_state = 2}, + [49] = {.lex_state = 0}, + [50] = {.lex_state = 0}, + [51] = {.lex_state = 2}, + [52] = {.lex_state = 0}, + [53] = {.lex_state = 2}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [STATE(0)] = { + [ts_builtin_sym_end] = ACTIONS(1), + [anon_sym_mod] = ACTIONS(1), + [anon_sym_SEMI] = ACTIONS(1), + [anon_sym_EQ] = ACTIONS(1), + [anon_sym_LBRACK] = ACTIONS(1), + [anon_sym_COMMA] = ACTIONS(1), + [anon_sym_RBRACK] = ACTIONS(1), + [anon_sym_COLON] = ACTIONS(1), + [anon_sym_LBRACE] = ACTIONS(1), + [anon_sym_RBRACE] = ACTIONS(1), + [anon_sym_SQUOTE] = ACTIONS(1), + [sym_escape_sequence] = ACTIONS(1), + [sym_identifier] = ACTIONS(1), + [sym_directive] = ACTIONS(1), + }, + [STATE(1)] = { + [sym_source_file] = STATE(52), + [sym__statement] = STATE(3), + [sym__directive_statement] = STATE(3), + [sym_mod_statement] = STATE(3), + [sym_assign_statement] = STATE(3), + [sym_expression] = STATE(3), + [sym__item_path] = STATE(16), + [sym_item_path] = STATE(21), + [sym_array] = STATE(21), + [sym_target] = STATE(21), + [sym_string_literal] = STATE(21), + [aux_sym_source_file_repeat1] = STATE(3), + [aux_sym__directive_statement_repeat1] = STATE(4), + [aux_sym__item_path_repeat1] = STATE(16), + [ts_builtin_sym_end] = ACTIONS(3), + [anon_sym_mod] = ACTIONS(5), + [anon_sym_COLON_COLON] = ACTIONS(7), + [anon_sym_LBRACK] = ACTIONS(9), + [anon_sym_SQUOTE] = ACTIONS(11), + [sym_identifier] = ACTIONS(13), + [sym_directive] = ACTIONS(15), + }, + [STATE(2)] = { + [sym__statement] = STATE(2), + [sym__directive_statement] = STATE(2), + [sym_mod_statement] = STATE(2), + [sym_assign_statement] = STATE(2), + [sym_expression] = STATE(2), + [sym__item_path] = STATE(16), + [sym_item_path] = STATE(21), + [sym_array] = STATE(21), + [sym_target] = STATE(21), + [sym_string_literal] = STATE(21), + [aux_sym_source_file_repeat1] = STATE(2), + [aux_sym__directive_statement_repeat1] = STATE(4), + [aux_sym__item_path_repeat1] = STATE(16), + [ts_builtin_sym_end] = ACTIONS(17), + [anon_sym_mod] = ACTIONS(19), + [anon_sym_COLON_COLON] = ACTIONS(22), + [anon_sym_LBRACK] = ACTIONS(25), + [anon_sym_SQUOTE] = ACTIONS(28), + [sym_identifier] = ACTIONS(31), + [sym_directive] = ACTIONS(34), + }, + [STATE(3)] = { + [sym__statement] = STATE(2), + [sym__directive_statement] = STATE(2), + [sym_mod_statement] = STATE(2), + [sym_assign_statement] = STATE(2), + [sym_expression] = STATE(2), + [sym__item_path] = STATE(16), + [sym_item_path] = STATE(21), + [sym_array] = STATE(21), + [sym_target] = STATE(21), + [sym_string_literal] = STATE(21), + [aux_sym_source_file_repeat1] = STATE(2), + [aux_sym__directive_statement_repeat1] = STATE(4), + [aux_sym__item_path_repeat1] = STATE(16), + [ts_builtin_sym_end] = ACTIONS(37), + [anon_sym_mod] = ACTIONS(5), + [anon_sym_COLON_COLON] = ACTIONS(7), + [anon_sym_LBRACK] = ACTIONS(9), + [anon_sym_SQUOTE] = ACTIONS(11), + [sym_identifier] = ACTIONS(13), + [sym_directive] = ACTIONS(15), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 9, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(39), 1, + sym_identifier, + ACTIONS(41), 1, + sym_directive, + STATE(29), 1, + aux_sym__directive_statement_repeat1, + STATE(16), 2, + sym__item_path, + aux_sym__item_path_repeat1, + STATE(28), 2, + sym_assign_statement, + sym_expression, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [33] = 9, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(43), 1, + anon_sym_RBRACK, + ACTIONS(45), 1, + sym_identifier, + STATE(16), 1, + sym__item_path, + STATE(30), 1, + aux_sym__item_path_repeat1, + STATE(35), 1, + sym_expression, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [64] = 9, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(45), 1, + sym_identifier, + ACTIONS(47), 1, + anon_sym_RBRACK, + STATE(16), 1, + sym__item_path, + STATE(30), 1, + aux_sym__item_path_repeat1, + STATE(44), 1, + sym_expression, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [95] = 9, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(45), 1, + sym_identifier, + ACTIONS(49), 1, + anon_sym_RBRACK, + STATE(16), 1, + sym__item_path, + STATE(30), 1, + aux_sym__item_path_repeat1, + STATE(44), 1, + sym_expression, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [126] = 4, + ACTIONS(55), 1, + anon_sym_COLON_COLON, + STATE(8), 1, + aux_sym__item_path_repeat1, + ACTIONS(53), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(51), 7, + ts_builtin_sym_end, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [146] = 7, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(45), 1, + sym_identifier, + STATE(27), 1, + sym_expression, + STATE(16), 2, + sym__item_path, + aux_sym__item_path_repeat1, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [172] = 8, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(45), 1, + sym_identifier, + STATE(16), 1, + sym__item_path, + STATE(30), 1, + aux_sym__item_path_repeat1, + STATE(46), 1, + sym_expression, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [200] = 8, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + ACTIONS(9), 1, + anon_sym_LBRACK, + ACTIONS(11), 1, + anon_sym_SQUOTE, + ACTIONS(45), 1, + sym_identifier, + STATE(16), 1, + sym__item_path, + STATE(30), 1, + aux_sym__item_path_repeat1, + STATE(44), 1, + sym_expression, + STATE(21), 4, + sym_item_path, + sym_array, + sym_target, + sym_string_literal, + [228] = 2, + ACTIONS(60), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(58), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [243] = 2, + ACTIONS(64), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(62), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [258] = 2, + ACTIONS(68), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(66), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [273] = 2, + ACTIONS(72), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(70), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [288] = 2, + ACTIONS(76), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(74), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [303] = 2, + ACTIONS(80), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(78), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [318] = 2, + ACTIONS(84), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(82), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [333] = 2, + ACTIONS(88), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(86), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [348] = 2, + ACTIONS(92), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(90), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [363] = 2, + ACTIONS(96), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(94), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [378] = 2, + ACTIONS(100), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(98), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [393] = 2, + ACTIONS(104), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(102), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [408] = 2, + ACTIONS(108), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(106), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [423] = 2, + ACTIONS(53), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(51), 8, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + anon_sym_SQUOTE, + sym_directive, + [438] = 2, + ACTIONS(112), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(110), 5, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_SQUOTE, + sym_directive, + [450] = 2, + ACTIONS(116), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(114), 5, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_SQUOTE, + sym_directive, + [462] = 2, + ACTIONS(120), 2, + anon_sym_mod, + sym_identifier, + ACTIONS(118), 5, + ts_builtin_sym_end, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_SQUOTE, + sym_directive, + [474] = 3, + ACTIONS(124), 1, + sym_directive, + STATE(29), 1, + aux_sym__directive_statement_repeat1, + ACTIONS(122), 4, + anon_sym_COLON_COLON, + anon_sym_LBRACK, + anon_sym_SQUOTE, + sym_identifier, + [487] = 3, + ACTIONS(7), 1, + anon_sym_COLON_COLON, + STATE(8), 1, + aux_sym__item_path_repeat1, + ACTIONS(127), 3, + anon_sym_COMMA, + anon_sym_RBRACK, + anon_sym_RBRACE, + [499] = 4, + ACTIONS(129), 1, + anon_sym_SQUOTE, + ACTIONS(131), 1, + aux_sym_string_literal_token1, + ACTIONS(133), 1, + sym_escape_sequence, + STATE(33), 1, + aux_sym_string_literal_repeat1, + [512] = 4, + ACTIONS(135), 1, + anon_sym_SQUOTE, + ACTIONS(137), 1, + aux_sym_string_literal_token1, + ACTIONS(139), 1, + sym_escape_sequence, + STATE(31), 1, + aux_sym_string_literal_repeat1, + [525] = 4, + ACTIONS(141), 1, + anon_sym_SQUOTE, + ACTIONS(143), 1, + aux_sym_string_literal_token1, + ACTIONS(146), 1, + sym_escape_sequence, + STATE(33), 1, + aux_sym_string_literal_repeat1, + [538] = 3, + ACTIONS(49), 1, + anon_sym_RBRACK, + ACTIONS(149), 1, + anon_sym_COMMA, + STATE(39), 1, + aux_sym_array_repeat1, + [548] = 3, + ACTIONS(151), 1, + anon_sym_COMMA, + ACTIONS(153), 1, + anon_sym_RBRACK, + STATE(34), 1, + aux_sym_array_repeat1, + [558] = 3, + ACTIONS(155), 1, + anon_sym_RBRACE, + ACTIONS(157), 1, + sym_identifier, + STATE(38), 1, + sym_argument, + [568] = 3, + ACTIONS(159), 1, + anon_sym_EQ, + ACTIONS(161), 1, + anon_sym_LBRACE, + STATE(15), 1, + sym__arguments, + [578] = 3, + ACTIONS(163), 1, + anon_sym_COMMA, + ACTIONS(165), 1, + anon_sym_RBRACE, + STATE(42), 1, + aux_sym__arguments_repeat1, + [588] = 3, + ACTIONS(167), 1, + anon_sym_COMMA, + ACTIONS(170), 1, + anon_sym_RBRACK, + STATE(39), 1, + aux_sym_array_repeat1, + [598] = 3, + ACTIONS(157), 1, + sym_identifier, + ACTIONS(172), 1, + anon_sym_RBRACE, + STATE(47), 1, + sym_argument, + [608] = 3, + ACTIONS(157), 1, + sym_identifier, + ACTIONS(174), 1, + anon_sym_RBRACE, + STATE(47), 1, + sym_argument, + [618] = 3, + ACTIONS(172), 1, + anon_sym_RBRACE, + ACTIONS(176), 1, + anon_sym_COMMA, + STATE(43), 1, + aux_sym__arguments_repeat1, + [628] = 3, + ACTIONS(178), 1, + anon_sym_COMMA, + ACTIONS(181), 1, + anon_sym_RBRACE, + STATE(43), 1, + aux_sym__arguments_repeat1, + [638] = 1, + ACTIONS(170), 2, + anon_sym_COMMA, + anon_sym_RBRACK, + [643] = 2, + ACTIONS(161), 1, + anon_sym_LBRACE, + STATE(15), 1, + sym__arguments, + [650] = 1, + ACTIONS(183), 2, + anon_sym_COMMA, + anon_sym_RBRACE, + [655] = 1, + ACTIONS(181), 2, + anon_sym_COMMA, + anon_sym_RBRACE, + [660] = 2, + ACTIONS(157), 1, + sym_identifier, + STATE(47), 1, + sym_argument, + [667] = 1, + ACTIONS(185), 1, + anon_sym_COLON, + [671] = 1, + ACTIONS(187), 1, + anon_sym_SEMI, + [675] = 1, + ACTIONS(189), 1, + sym_identifier, + [679] = 1, + ACTIONS(191), 1, + ts_builtin_sym_end, + [683] = 1, + ACTIONS(193), 1, + sym_identifier, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(4)] = 0, + [SMALL_STATE(5)] = 33, + [SMALL_STATE(6)] = 64, + [SMALL_STATE(7)] = 95, + [SMALL_STATE(8)] = 126, + [SMALL_STATE(9)] = 146, + [SMALL_STATE(10)] = 172, + [SMALL_STATE(11)] = 200, + [SMALL_STATE(12)] = 228, + [SMALL_STATE(13)] = 243, + [SMALL_STATE(14)] = 258, + [SMALL_STATE(15)] = 273, + [SMALL_STATE(16)] = 288, + [SMALL_STATE(17)] = 303, + [SMALL_STATE(18)] = 318, + [SMALL_STATE(19)] = 333, + [SMALL_STATE(20)] = 348, + [SMALL_STATE(21)] = 363, + [SMALL_STATE(22)] = 378, + [SMALL_STATE(23)] = 393, + [SMALL_STATE(24)] = 408, + [SMALL_STATE(25)] = 423, + [SMALL_STATE(26)] = 438, + [SMALL_STATE(27)] = 450, + [SMALL_STATE(28)] = 462, + [SMALL_STATE(29)] = 474, + [SMALL_STATE(30)] = 487, + [SMALL_STATE(31)] = 499, + [SMALL_STATE(32)] = 512, + [SMALL_STATE(33)] = 525, + [SMALL_STATE(34)] = 538, + [SMALL_STATE(35)] = 548, + [SMALL_STATE(36)] = 558, + [SMALL_STATE(37)] = 568, + [SMALL_STATE(38)] = 578, + [SMALL_STATE(39)] = 588, + [SMALL_STATE(40)] = 598, + [SMALL_STATE(41)] = 608, + [SMALL_STATE(42)] = 618, + [SMALL_STATE(43)] = 628, + [SMALL_STATE(44)] = 638, + [SMALL_STATE(45)] = 643, + [SMALL_STATE(46)] = 650, + [SMALL_STATE(47)] = 655, + [SMALL_STATE(48)] = 660, + [SMALL_STATE(49)] = 667, + [SMALL_STATE(50)] = 671, + [SMALL_STATE(51)] = 675, + [SMALL_STATE(52)] = 679, + [SMALL_STATE(53)] = 683, +}; + +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(51), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(53), + [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), + [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(32), + [13] = {.entry = {.count = 1, .reusable = false}}, SHIFT(37), + [15] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [17] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), + [19] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(51), + [22] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(53), + [25] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(5), + [28] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(32), + [31] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(37), + [34] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(4), + [37] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0), + [39] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), + [41] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), + [43] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [45] = {.entry = {.count = 1, .reusable = true}}, SHIFT(45), + [47] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), + [49] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [51] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__item_path_repeat1, 2, 0, 0), + [53] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__item_path_repeat1, 2, 0, 0), + [55] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__item_path_repeat1, 2, 0, 0), SHIFT_REPEAT(53), + [58] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__arguments, 3, 0, 0), + [60] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__arguments, 3, 0, 0), + [62] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 2, 0, 0), + [64] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 2, 0, 0), + [66] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string_literal, 2, 0, 0), + [68] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_string_literal, 2, 0, 0), + [70] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_target, 2, 0, 0), + [72] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_target, 2, 0, 0), + [74] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_item_path, 1, 0, 0), + [76] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_item_path, 1, 0, 0), + [78] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 3, 0, 0), + [80] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 3, 0, 0), + [82] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string_literal, 3, 0, 0), + [84] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_string_literal, 3, 0, 0), + [86] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__arguments, 2, 0, 0), + [88] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__arguments, 2, 0, 0), + [90] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 4, 0, 0), + [92] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 4, 0, 0), + [94] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_expression, 1, 0, 0), + [96] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_expression, 1, 0, 0), + [98] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 5, 0, 0), + [100] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 5, 0, 0), + [102] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__arguments, 4, 0, 0), + [104] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__arguments, 4, 0, 0), + [106] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__arguments, 5, 0, 0), + [108] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__arguments, 5, 0, 0), + [110] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_mod_statement, 3, 0, 0), + [112] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_mod_statement, 3, 0, 0), + [114] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_assign_statement, 3, 0, 0), + [116] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_assign_statement, 3, 0, 0), + [118] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__directive_statement, 2, 0, 0), + [120] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__directive_statement, 2, 0, 0), + [122] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__directive_statement_repeat1, 2, 0, 0), + [124] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__directive_statement_repeat1, 2, 0, 0), SHIFT_REPEAT(29), + [127] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__item_path, 1, 0, 0), + [129] = {.entry = {.count = 1, .reusable = false}}, SHIFT(18), + [131] = {.entry = {.count = 1, .reusable = true}}, SHIFT(33), + [133] = {.entry = {.count = 1, .reusable = false}}, SHIFT(33), + [135] = {.entry = {.count = 1, .reusable = false}}, SHIFT(14), + [137] = {.entry = {.count = 1, .reusable = true}}, SHIFT(31), + [139] = {.entry = {.count = 1, .reusable = false}}, SHIFT(31), + [141] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_string_literal_repeat1, 2, 0, 0), + [143] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_string_literal_repeat1, 2, 0, 0), SHIFT_REPEAT(33), + [146] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_string_literal_repeat1, 2, 0, 0), SHIFT_REPEAT(33), + [149] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6), + [151] = {.entry = {.count = 1, .reusable = true}}, SHIFT(7), + [153] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), + [155] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), + [157] = {.entry = {.count = 1, .reusable = true}}, SHIFT(49), + [159] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), + [161] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36), + [163] = {.entry = {.count = 1, .reusable = true}}, SHIFT(40), + [165] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [167] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2, 0, 0), SHIFT_REPEAT(11), + [170] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2, 0, 0), + [172] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), + [174] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), + [176] = {.entry = {.count = 1, .reusable = true}}, SHIFT(41), + [178] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__arguments_repeat1, 2, 0, 0), SHIFT_REPEAT(48), + [181] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__arguments_repeat1, 2, 0, 0), + [183] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_argument, 3, 0, 0), + [185] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), + [187] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26), + [189] = {.entry = {.count = 1, .reusable = true}}, SHIFT(50), + [191] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [193] = {.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_vvk(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, + .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 = "vvk", + .max_reserved_word_set_size = 0, + .metadata = { + .major_version = 0, + .minor_version = 1, + .patch_version = 0, + }, + }; + return &language; +} +#ifdef __cplusplus +} +#endif diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h new file mode 100644 index 0000000..1abdd12 --- /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 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/src/tree_sitter/array.h b/src/tree_sitter/array.h new file mode 100644 index 0000000..a17a574 --- /dev/null +++ b/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/src/tree_sitter/parser.h b/src/tree_sitter/parser.h new file mode 100644 index 0000000..858107d --- /dev/null +++ b/src/tree_sitter/parser.h @@ -0,0 +1,286 @@ +#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 { + 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_