diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-14 19:59:18 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-14 19:59:33 +0100 |
| commit | 9b7bda28db0200b628e5f6eb7021a5a717db2e73 (patch) | |
| tree | 2f477b0fe308da3554fbd0ab807c4c4725715311 /src | |
Initial grammar
Diffstat (limited to 'src')
| -rw-r--r-- | src/grammar.json | 479 | ||||
| -rw-r--r-- | src/node-types.json | 375 | ||||
| -rw-r--r-- | src/parser.c | 1553 | ||||
| -rw-r--r-- | src/tree_sitter/alloc.h | 54 | ||||
| -rw-r--r-- | src/tree_sitter/array.h | 291 | ||||
| -rw-r--r-- | src/tree_sitter/parser.h | 286 |
6 files changed, 3038 insertions, 0 deletions
diff --git a/src/grammar.json b/src/grammar.json new file mode 100644 index 0000000..de08260 --- /dev/null +++ b/src/grammar.json @@ -0,0 +1,479 @@ +{ + "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", + "name": "wmap", + "rules": { + "source_file": { + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "entity" + }, + { + "type": "SYMBOL", + "name": "_line_ending" + } + ] + }, + { + "type": "SYMBOL", + "name": "_line_ending" + } + ] + } + }, + "entity": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "component" + }, + { + "type": "SYMBOL", + "name": "dependency" + }, + { + "type": "SYMBOL", + "name": "note" + }, + { + "type": "SYMBOL", + "name": "stage" + }, + { + "type": "SYMBOL", + "name": "group" + }, + { + "type": "SYMBOL", + "name": "inertia" + }, + { + "type": "SYMBOL", + "name": "evolution" + } + ] + }, + "component": { + "type": "SEQ", + "members": [ + { + "type": "FIELD", + "name": "label", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + }, + { + "type": "FIELD", + "name": "position", + "content": { + "type": "SYMBOL", + "name": "position" + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "FIELD", + "name": "shape", + "content": { + "type": "SYMBOL", + "name": "shape" + } + }, + { + "type": "BLANK" + } + ] + } + ] + }, + "dependency": { + "type": "SEQ", + "members": [ + { + "type": "FIELD", + "name": "from", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + }, + { + "type": "FIELD", + "name": "type", + "content": { + "type": "SYMBOL", + "name": "dependency_type" + } + }, + { + "type": "FIELD", + "name": "to", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + } + ] + }, + "note": { + "type": "SEQ", + "members": [ + { + "type": "ALIAS", + "content": { + "type": "SYMBOL", + "name": "_note_keyword" + }, + "named": false, + "value": "keyword" + }, + { + "type": "FIELD", + "name": "position", + "content": { + "type": "SYMBOL", + "name": "position" + } + }, + { + "type": "FIELD", + "name": "text", + "content": { + "type": "SYMBOL", + "name": "text" + } + } + ] + }, + "stage": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "FIELD", + "name": "number", + "content": { + "type": "SYMBOL", + "name": "stage_number" + } + }, + { + "type": "STRING", + "value": "]" + }, + { + "type": "FIELD", + "name": "value", + "content": { + "type": "SYMBOL", + "name": "real_number" + } + } + ] + }, + "group": { + "type": "SEQ", + "members": [ + { + "type": "ALIAS", + "content": { + "type": "SYMBOL", + "name": "_group_keyword" + }, + "named": false, + "value": "keyword" + }, + { + "type": "FIELD", + "name": "component", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "FIELD", + "name": "component", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + } + ] + } + } + ] + }, + "inertia": { + "type": "SEQ", + "members": [ + { + "type": "ALIAS", + "content": { + "type": "SYMBOL", + "name": "_inertia_keyword" + }, + "named": false, + "value": "keyword" + }, + { + "type": "FIELD", + "name": "component", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + } + ] + }, + "evolution": { + "type": "SEQ", + "members": [ + { + "type": "ALIAS", + "content": { + "type": "SYMBOL", + "name": "_evolution_keyword" + }, + "named": false, + "value": "keyword" + }, + { + "type": "FIELD", + "name": "component", + "content": { + "type": "SYMBOL", + "name": "component_label" + } + }, + { + "type": "FIELD", + "name": "sign", + "content": { + "type": "SYMBOL", + "name": "sign" + } + }, + { + "type": "FIELD", + "name": "value", + "content": { + "type": "SYMBOL", + "name": "real_number" + } + } + ] + }, + "position": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "(" + }, + { + "type": "FIELD", + "name": "x", + "content": { + "type": "SYMBOL", + "name": "real_number" + } + }, + { + "type": "STRING", + "value": "," + }, + { + "type": "FIELD", + "name": "y", + "content": { + "type": "SYMBOL", + "name": "real_number" + } + }, + { + "type": "STRING", + "value": ")" + } + ] + }, + "shape": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "SYMBOL", + "name": "shape_label" + }, + { + "type": "STRING", + "value": "]" + } + ] + }, + "dependency_type": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "--" + }, + { + "type": "STRING", + "value": "->" + } + ] + }, + "sign": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "+" + }, + { + "type": "STRING", + "value": "-" + } + ] + }, + "component_label": { + "type": "PATTERN", + "value": "[^\\-+,\\[\\]()\\n\\r]+" + }, + "text": { + "type": "PATTERN", + "value": "[^\\n\\r]+" + }, + "real_number": { + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "[0-9]+\\.[0-9]*" + }, + { + "type": "PATTERN", + "value": "[0-9]+" + }, + { + "type": "PATTERN", + "value": "\\.[0-9]+" + } + ] + }, + "stage_number": { + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "[Ii][Vv]" + }, + { + "type": "PATTERN", + "value": "[Ii][Ii][Ii]" + }, + { + "type": "PATTERN", + "value": "[Ii][Ii]" + }, + { + "type": "PATTERN", + "value": "[Ii]" + } + ] + }, + "shape_label": { + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "[Xx]" + }, + { + "type": "PATTERN", + "value": "[Ss][Qq][Uu][Aa][Rr][Ee]" + }, + { + "type": "PATTERN", + "value": "[Tt][Rr][Ii][Aa][Nn][Gg][Ll][Ee]" + }, + { + "type": "PATTERN", + "value": "[Cc][Ii][Rr][Cc][Ll][Ee]" + } + ] + }, + "_note_keyword": { + "type": "PATTERN", + "value": "\\[[Nn][Oo][Tt][Ee]\\]" + }, + "_group_keyword": { + "type": "PATTERN", + "value": "\\[[Gg][Rr][Oo][Uu][Pp]\\]" + }, + "_inertia_keyword": { + "type": "PATTERN", + "value": "\\[[Ii][Nn][Ee][Rr][Tt][Ii][Aa]\\]" + }, + "_evolution_keyword": { + "type": "PATTERN", + "value": "\\[[Ee][Vv][Oo][Ll][Uu][Tt][Ii][Oo][Nn]\\]" + }, + "_line_ending": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "\n" + }, + { + "type": "STRING", + "value": "\r\n" + }, + { + "type": "STRING", + "value": "\r" + } + ] + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "[ \\t]" + } + ], + "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..c328029 --- /dev/null +++ b/src/node-types.json @@ -0,0 +1,375 @@ +[ + { + "type": "component", + "named": true, + "fields": { + "label": { + "multiple": false, + "required": true, + "types": [ + { + "type": "component_label", + "named": true + } + ] + }, + "position": { + "multiple": false, + "required": true, + "types": [ + { + "type": "position", + "named": true + } + ] + }, + "shape": { + "multiple": false, + "required": false, + "types": [ + { + "type": "shape", + "named": true + } + ] + } + } + }, + { + "type": "dependency", + "named": true, + "fields": { + "from": { + "multiple": false, + "required": true, + "types": [ + { + "type": "component_label", + "named": true + } + ] + }, + "to": { + "multiple": false, + "required": true, + "types": [ + { + "type": "component_label", + "named": true + } + ] + }, + "type": { + "multiple": false, + "required": true, + "types": [ + { + "type": "dependency_type", + "named": true + } + ] + } + } + }, + { + "type": "dependency_type", + "named": true, + "fields": {} + }, + { + "type": "entity", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "component", + "named": true + }, + { + "type": "dependency", + "named": true + }, + { + "type": "evolution", + "named": true + }, + { + "type": "group", + "named": true + }, + { + "type": "inertia", + "named": true + }, + { + "type": "note", + "named": true + }, + { + "type": "stage", + "named": true + } + ] + } + }, + { + "type": "evolution", + "named": true, + "fields": { + "component": { + "multiple": false, + "required": true, + "types": [ + { + "type": "component_label", + "named": true + } + ] + }, + "sign": { + "multiple": false, + "required": true, + "types": [ + { + "type": "sign", + "named": true + } + ] + }, + "value": { + "multiple": false, + "required": true, + "types": [ + { + "type": "real_number", + "named": true + } + ] + } + } + }, + { + "type": "group", + "named": true, + "fields": { + "component": { + "multiple": true, + "required": true, + "types": [ + { + "type": "component_label", + "named": true + } + ] + } + } + }, + { + "type": "inertia", + "named": true, + "fields": { + "component": { + "multiple": false, + "required": true, + "types": [ + { + "type": "component_label", + "named": true + } + ] + } + } + }, + { + "type": "note", + "named": true, + "fields": { + "position": { + "multiple": false, + "required": true, + "types": [ + { + "type": "position", + "named": true + } + ] + }, + "text": { + "multiple": false, + "required": true, + "types": [ + { + "type": "text", + "named": true + } + ] + } + } + }, + { + "type": "position", + "named": true, + "fields": { + "x": { + "multiple": false, + "required": true, + "types": [ + { + "type": "real_number", + "named": true + } + ] + }, + "y": { + "multiple": false, + "required": true, + "types": [ + { + "type": "real_number", + "named": true + } + ] + } + } + }, + { + "type": "real_number", + "named": true, + "fields": {} + }, + { + "type": "shape", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "shape_label", + "named": true + } + ] + } + }, + { + "type": "shape_label", + "named": true, + "fields": {} + }, + { + "type": "sign", + "named": true, + "fields": {} + }, + { + "type": "source_file", + "named": true, + "root": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "entity", + "named": true + } + ] + } + }, + { + "type": "stage", + "named": true, + "fields": { + "number": { + "multiple": false, + "required": true, + "types": [ + { + "type": "stage_number", + "named": true + } + ] + }, + "value": { + "multiple": false, + "required": true, + "types": [ + { + "type": "real_number", + "named": true + } + ] + } + } + }, + { + "type": "stage_number", + "named": true, + "fields": {} + }, + { + "type": "\n", + "named": false + }, + { + "type": "\r", + "named": false + }, + { + "type": "\r\n", + "named": false + }, + { + "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": "]", + "named": false + }, + { + "type": "component_label", + "named": true + }, + { + "type": "keyword", + "named": false + }, + { + "type": "text", + "named": true + } +]
\ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..71363fc --- /dev/null +++ b/src/parser.c @@ -0,0 +1,1553 @@ +/* Automatically @generated by tree-sitter */ + +#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 50 +#define LARGE_STATE_COUNT 2 +#define SYMBOL_COUNT 49 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 30 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 13 +#define MAX_ALIAS_SEQUENCE_LENGTH 5 +#define MAX_RESERVED_WORD_SET_SIZE 0 +#define PRODUCTION_ID_COUNT 11 +#define SUPERTYPE_COUNT 0 + +enum ts_symbol_identifiers { + anon_sym_LBRACK = 1, + anon_sym_RBRACK = 2, + anon_sym_COMMA = 3, + anon_sym_LPAREN = 4, + anon_sym_RPAREN = 5, + anon_sym_DASH_DASH = 6, + anon_sym_DASH_GT = 7, + anon_sym_PLUS = 8, + anon_sym_DASH = 9, + sym_component_label = 10, + sym_text = 11, + aux_sym_real_number_token1 = 12, + aux_sym_real_number_token2 = 13, + aux_sym_real_number_token3 = 14, + aux_sym_stage_number_token1 = 15, + aux_sym_stage_number_token2 = 16, + aux_sym_stage_number_token3 = 17, + aux_sym_stage_number_token4 = 18, + aux_sym_shape_label_token1 = 19, + aux_sym_shape_label_token2 = 20, + aux_sym_shape_label_token3 = 21, + aux_sym_shape_label_token4 = 22, + sym__note_keyword = 23, + sym__group_keyword = 24, + sym__inertia_keyword = 25, + sym__evolution_keyword = 26, + anon_sym_LF = 27, + anon_sym_CR_LF = 28, + anon_sym_CR = 29, + sym_source_file = 30, + sym_entity = 31, + sym_component = 32, + sym_dependency = 33, + sym_note = 34, + sym_stage = 35, + sym_group = 36, + sym_inertia = 37, + sym_evolution = 38, + sym_position = 39, + sym_shape = 40, + sym_dependency_type = 41, + sym_sign = 42, + sym_real_number = 43, + sym_stage_number = 44, + sym_shape_label = 45, + sym__line_ending = 46, + aux_sym_source_file_repeat1 = 47, + aux_sym_group_repeat1 = 48, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [anon_sym_LBRACK] = "[", + [anon_sym_RBRACK] = "]", + [anon_sym_COMMA] = ",", + [anon_sym_LPAREN] = "(", + [anon_sym_RPAREN] = ")", + [anon_sym_DASH_DASH] = "--", + [anon_sym_DASH_GT] = "->", + [anon_sym_PLUS] = "+", + [anon_sym_DASH] = "-", + [sym_component_label] = "component_label", + [sym_text] = "text", + [aux_sym_real_number_token1] = "real_number_token1", + [aux_sym_real_number_token2] = "real_number_token2", + [aux_sym_real_number_token3] = "real_number_token3", + [aux_sym_stage_number_token1] = "stage_number_token1", + [aux_sym_stage_number_token2] = "stage_number_token2", + [aux_sym_stage_number_token3] = "stage_number_token3", + [aux_sym_stage_number_token4] = "stage_number_token4", + [aux_sym_shape_label_token1] = "shape_label_token1", + [aux_sym_shape_label_token2] = "shape_label_token2", + [aux_sym_shape_label_token3] = "shape_label_token3", + [aux_sym_shape_label_token4] = "shape_label_token4", + [sym__note_keyword] = "keyword", + [sym__group_keyword] = "keyword", + [sym__inertia_keyword] = "keyword", + [sym__evolution_keyword] = "keyword", + [anon_sym_LF] = "\n", + [anon_sym_CR_LF] = "\r\n", + [anon_sym_CR] = "\r", + [sym_source_file] = "source_file", + [sym_entity] = "entity", + [sym_component] = "component", + [sym_dependency] = "dependency", + [sym_note] = "note", + [sym_stage] = "stage", + [sym_group] = "group", + [sym_inertia] = "inertia", + [sym_evolution] = "evolution", + [sym_position] = "position", + [sym_shape] = "shape", + [sym_dependency_type] = "dependency_type", + [sym_sign] = "sign", + [sym_real_number] = "real_number", + [sym_stage_number] = "stage_number", + [sym_shape_label] = "shape_label", + [sym__line_ending] = "_line_ending", + [aux_sym_source_file_repeat1] = "source_file_repeat1", + [aux_sym_group_repeat1] = "group_repeat1", +}; + +static const TSSymbol ts_symbol_map[] = { + [ts_builtin_sym_end] = ts_builtin_sym_end, + [anon_sym_LBRACK] = anon_sym_LBRACK, + [anon_sym_RBRACK] = anon_sym_RBRACK, + [anon_sym_COMMA] = anon_sym_COMMA, + [anon_sym_LPAREN] = anon_sym_LPAREN, + [anon_sym_RPAREN] = anon_sym_RPAREN, + [anon_sym_DASH_DASH] = anon_sym_DASH_DASH, + [anon_sym_DASH_GT] = anon_sym_DASH_GT, + [anon_sym_PLUS] = anon_sym_PLUS, + [anon_sym_DASH] = anon_sym_DASH, + [sym_component_label] = sym_component_label, + [sym_text] = sym_text, + [aux_sym_real_number_token1] = aux_sym_real_number_token1, + [aux_sym_real_number_token2] = aux_sym_real_number_token2, + [aux_sym_real_number_token3] = aux_sym_real_number_token3, + [aux_sym_stage_number_token1] = aux_sym_stage_number_token1, + [aux_sym_stage_number_token2] = aux_sym_stage_number_token2, + [aux_sym_stage_number_token3] = aux_sym_stage_number_token3, + [aux_sym_stage_number_token4] = aux_sym_stage_number_token4, + [aux_sym_shape_label_token1] = aux_sym_shape_label_token1, + [aux_sym_shape_label_token2] = aux_sym_shape_label_token2, + [aux_sym_shape_label_token3] = aux_sym_shape_label_token3, + [aux_sym_shape_label_token4] = aux_sym_shape_label_token4, + [sym__note_keyword] = sym__note_keyword, + [sym__group_keyword] = sym__note_keyword, + [sym__inertia_keyword] = sym__note_keyword, + [sym__evolution_keyword] = sym__note_keyword, + [anon_sym_LF] = anon_sym_LF, + [anon_sym_CR_LF] = anon_sym_CR_LF, + [anon_sym_CR] = anon_sym_CR, + [sym_source_file] = sym_source_file, + [sym_entity] = sym_entity, + [sym_component] = sym_component, + [sym_dependency] = sym_dependency, + [sym_note] = sym_note, + [sym_stage] = sym_stage, + [sym_group] = sym_group, + [sym_inertia] = sym_inertia, + [sym_evolution] = sym_evolution, + [sym_position] = sym_position, + [sym_shape] = sym_shape, + [sym_dependency_type] = sym_dependency_type, + [sym_sign] = sym_sign, + [sym_real_number] = sym_real_number, + [sym_stage_number] = sym_stage_number, + [sym_shape_label] = sym_shape_label, + [sym__line_ending] = sym__line_ending, + [aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1, + [aux_sym_group_repeat1] = aux_sym_group_repeat1, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [anon_sym_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_COMMA] = { + .visible = true, + .named = false, + }, + [anon_sym_LPAREN] = { + .visible = true, + .named = false, + }, + [anon_sym_RPAREN] = { + .visible = true, + .named = false, + }, + [anon_sym_DASH_DASH] = { + .visible = true, + .named = false, + }, + [anon_sym_DASH_GT] = { + .visible = true, + .named = false, + }, + [anon_sym_PLUS] = { + .visible = true, + .named = false, + }, + [anon_sym_DASH] = { + .visible = true, + .named = false, + }, + [sym_component_label] = { + .visible = true, + .named = true, + }, + [sym_text] = { + .visible = true, + .named = true, + }, + [aux_sym_real_number_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_real_number_token2] = { + .visible = false, + .named = false, + }, + [aux_sym_real_number_token3] = { + .visible = false, + .named = false, + }, + [aux_sym_stage_number_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_stage_number_token2] = { + .visible = false, + .named = false, + }, + [aux_sym_stage_number_token3] = { + .visible = false, + .named = false, + }, + [aux_sym_stage_number_token4] = { + .visible = false, + .named = false, + }, + [aux_sym_shape_label_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_shape_label_token2] = { + .visible = false, + .named = false, + }, + [aux_sym_shape_label_token3] = { + .visible = false, + .named = false, + }, + [aux_sym_shape_label_token4] = { + .visible = false, + .named = false, + }, + [sym__note_keyword] = { + .visible = true, + .named = false, + }, + [sym__group_keyword] = { + .visible = true, + .named = false, + }, + [sym__inertia_keyword] = { + .visible = true, + .named = false, + }, + [sym__evolution_keyword] = { + .visible = true, + .named = false, + }, + [anon_sym_LF] = { + .visible = true, + .named = false, + }, + [anon_sym_CR_LF] = { + .visible = true, + .named = false, + }, + [anon_sym_CR] = { + .visible = true, + .named = false, + }, + [sym_source_file] = { + .visible = true, + .named = true, + }, + [sym_entity] = { + .visible = true, + .named = true, + }, + [sym_component] = { + .visible = true, + .named = true, + }, + [sym_dependency] = { + .visible = true, + .named = true, + }, + [sym_note] = { + .visible = true, + .named = true, + }, + [sym_stage] = { + .visible = true, + .named = true, + }, + [sym_group] = { + .visible = true, + .named = true, + }, + [sym_inertia] = { + .visible = true, + .named = true, + }, + [sym_evolution] = { + .visible = true, + .named = true, + }, + [sym_position] = { + .visible = true, + .named = true, + }, + [sym_shape] = { + .visible = true, + .named = true, + }, + [sym_dependency_type] = { + .visible = true, + .named = true, + }, + [sym_sign] = { + .visible = true, + .named = true, + }, + [sym_real_number] = { + .visible = true, + .named = true, + }, + [sym_stage_number] = { + .visible = true, + .named = true, + }, + [sym_shape_label] = { + .visible = true, + .named = true, + }, + [sym__line_ending] = { + .visible = false, + .named = true, + }, + [aux_sym_source_file_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_group_repeat1] = { + .visible = false, + .named = false, + }, +}; + +enum ts_field_identifiers { + field_component = 1, + field_from = 2, + field_label = 3, + field_number = 4, + field_position = 5, + field_shape = 6, + field_sign = 7, + field_text = 8, + field_to = 9, + field_type = 10, + field_value = 11, + field_x = 12, + field_y = 13, +}; + +static const char * const ts_field_names[] = { + [0] = NULL, + [field_component] = "component", + [field_from] = "from", + [field_label] = "label", + [field_number] = "number", + [field_position] = "position", + [field_shape] = "shape", + [field_sign] = "sign", + [field_text] = "text", + [field_to] = "to", + [field_type] = "type", + [field_value] = "value", + [field_x] = "x", + [field_y] = "y", +}; + +static const TSMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { + [1] = {.index = 0, .length = 2}, + [2] = {.index = 2, .length = 1}, + [3] = {.index = 3, .length = 3}, + [4] = {.index = 6, .length = 3}, + [5] = {.index = 9, .length = 2}, + [6] = {.index = 11, .length = 2}, + [7] = {.index = 13, .length = 2}, + [8] = {.index = 15, .length = 2}, + [9] = {.index = 17, .length = 3}, + [10] = {.index = 20, .length = 2}, +}; + +static const TSFieldMapEntry ts_field_map_entries[] = { + [0] = + {field_label, 0}, + {field_position, 1}, + [2] = + {field_component, 1}, + [3] = + {field_label, 0}, + {field_position, 1}, + {field_shape, 2}, + [6] = + {field_from, 0}, + {field_to, 2}, + {field_type, 1}, + [9] = + {field_position, 1}, + {field_text, 2}, + [11] = + {field_component, 1}, + {field_component, 2, .inherited = true}, + [13] = + {field_number, 1}, + {field_value, 3}, + [15] = + {field_component, 0, .inherited = true}, + {field_component, 1, .inherited = true}, + [17] = + {field_component, 1}, + {field_sign, 2}, + {field_value, 3}, + [20] = + {field_x, 1}, + {field_y, 3}, +}; + +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] = 14, + [17] = 17, + [18] = 18, + [19] = 19, + [20] = 20, + [21] = 18, + [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] = 20, + [46] = 44, + [47] = 47, + [48] = 33, + [49] = 49, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(49); + ADVANCE_MAP( + '\n', 80, + '\r', 82, + '(', 54, + ')', 55, + '+', 58, + ',', 53, + '-', 60, + '.', 47, + '[', 51, + ']', 52, + ); + if (lookahead == '\t' || + lookahead == ' ') SKIP(0); + if (lookahead == 'C' || + lookahead == 'c') ADVANCE(20); + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(71); + if (lookahead == 'S' || + lookahead == 's') ADVANCE(34); + if (lookahead == 'T' || + lookahead == 't') ADVANCE(36); + if (lookahead == 'X' || + lookahead == 'x') ADVANCE(72); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(66); + END_STATE(); + case 1: + if (lookahead == '\n') ADVANCE(80); + if (lookahead == '\r') ADVANCE(82); + if (lookahead == '(') ADVANCE(54); + if (lookahead == '-') ADVANCE(3); + if (lookahead == '[') ADVANCE(50); + if (lookahead == '\t' || + lookahead == ' ') SKIP(1); + END_STATE(); + case 2: + if (lookahead == '+') ADVANCE(58); + if (lookahead == '-') ADVANCE(59); + if (lookahead == '\t' || + lookahead == ' ') SKIP(2); + END_STATE(); + case 3: + if (lookahead == '-') ADVANCE(56); + if (lookahead == '>') ADVANCE(57); + END_STATE(); + case 4: + if (lookahead == ']') ADVANCE(76); + END_STATE(); + case 5: + if (lookahead == ']') ADVANCE(77); + END_STATE(); + case 6: + if (lookahead == ']') ADVANCE(78); + END_STATE(); + case 7: + if (lookahead == ']') ADVANCE(79); + END_STATE(); + case 8: + if (lookahead == '\t' || + lookahead == ' ') ADVANCE(63); + if (lookahead != 0 && + lookahead != '\t' && + lookahead != '\n' && + lookahead != '\r') ADVANCE(64); + END_STATE(); + case 9: + if (lookahead == 'A' || + lookahead == 'a') ADVANCE(27); + END_STATE(); + case 10: + if (lookahead == 'A' || + lookahead == 'a') ADVANCE(6); + END_STATE(); + case 11: + if (lookahead == 'A' || + lookahead == 'a') ADVANCE(39); + END_STATE(); + case 12: + if (lookahead == 'C' || + lookahead == 'c') ADVANCE(24); + END_STATE(); + case 13: + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(4); + END_STATE(); + case 14: + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(75); + END_STATE(); + case 15: + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(73); + END_STATE(); + case 16: + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(74); + END_STATE(); + case 17: + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(37); + END_STATE(); + case 18: + if (lookahead == 'G' || + lookahead == 'g') ADVANCE(25); + END_STATE(); + case 19: + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(9); + END_STATE(); + case 20: + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(35); + END_STATE(); + case 21: + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(10); + END_STATE(); + case 22: + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(32); + END_STATE(); + case 23: + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(45); + END_STATE(); + case 24: + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(14); + END_STATE(); + case 25: + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(16); + END_STATE(); + case 26: + if (lookahead == 'N' || + lookahead == 'n') ADVANCE(17); + END_STATE(); + case 27: + if (lookahead == 'N' || + lookahead == 'n') ADVANCE(18); + END_STATE(); + case 28: + if (lookahead == 'N' || + lookahead == 'n') ADVANCE(7); + END_STATE(); + case 29: + if (lookahead == 'O' || + lookahead == 'o') ADVANCE(40); + END_STATE(); + case 30: + if (lookahead == 'O' || + lookahead == 'o') ADVANCE(23); + END_STATE(); + case 31: + if (lookahead == 'O' || + lookahead == 'o') ADVANCE(44); + END_STATE(); + case 32: + if (lookahead == 'O' || + lookahead == 'o') ADVANCE(28); + END_STATE(); + case 33: + if (lookahead == 'P' || + lookahead == 'p') ADVANCE(5); + END_STATE(); + case 34: + if (lookahead == 'Q' || + lookahead == 'q') ADVANCE(43); + END_STATE(); + case 35: + if (lookahead == 'R' || + lookahead == 'r') ADVANCE(12); + END_STATE(); + case 36: + if (lookahead == 'R' || + lookahead == 'r') ADVANCE(19); + END_STATE(); + case 37: + if (lookahead == 'R' || + lookahead == 'r') ADVANCE(42); + END_STATE(); + case 38: + if (lookahead == 'R' || + lookahead == 'r') ADVANCE(31); + END_STATE(); + case 39: + if (lookahead == 'R' || + lookahead == 'r') ADVANCE(15); + END_STATE(); + case 40: + if (lookahead == 'T' || + lookahead == 't') ADVANCE(13); + END_STATE(); + case 41: + if (lookahead == 'T' || + lookahead == 't') ADVANCE(22); + END_STATE(); + case 42: + if (lookahead == 'T' || + lookahead == 't') ADVANCE(21); + END_STATE(); + case 43: + if (lookahead == 'U' || + lookahead == 'u') ADVANCE(11); + END_STATE(); + case 44: + if (lookahead == 'U' || + lookahead == 'u') ADVANCE(33); + END_STATE(); + case 45: + if (lookahead == 'U' || + lookahead == 'u') ADVANCE(41); + END_STATE(); + case 46: + if (lookahead == 'V' || + lookahead == 'v') ADVANCE(30); + END_STATE(); + case 47: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(67); + END_STATE(); + case 48: + if (eof) ADVANCE(49); + if (lookahead == '\n') ADVANCE(80); + if (lookahead == '\r') ADVANCE(82); + if (lookahead == '[') ADVANCE(51); + if (lookahead == '\t' || + lookahead == ' ') ADVANCE(61); + if (lookahead != 0 && + lookahead != '(' && + lookahead != ')' && + (lookahead < '+' || '-' < lookahead) && + lookahead != ']') ADVANCE(62); + END_STATE(); + case 49: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 50: + ACCEPT_TOKEN(anon_sym_LBRACK); + END_STATE(); + case 51: + ACCEPT_TOKEN(anon_sym_LBRACK); + ADVANCE_MAP( + 'E', 46, + 'e', 46, + 'G', 38, + 'g', 38, + 'I', 26, + 'i', 26, + 'N', 29, + 'n', 29, + ); + END_STATE(); + case 52: + ACCEPT_TOKEN(anon_sym_RBRACK); + END_STATE(); + case 53: + ACCEPT_TOKEN(anon_sym_COMMA); + END_STATE(); + case 54: + ACCEPT_TOKEN(anon_sym_LPAREN); + END_STATE(); + case 55: + ACCEPT_TOKEN(anon_sym_RPAREN); + END_STATE(); + case 56: + ACCEPT_TOKEN(anon_sym_DASH_DASH); + END_STATE(); + case 57: + ACCEPT_TOKEN(anon_sym_DASH_GT); + END_STATE(); + case 58: + ACCEPT_TOKEN(anon_sym_PLUS); + END_STATE(); + case 59: + ACCEPT_TOKEN(anon_sym_DASH); + END_STATE(); + case 60: + ACCEPT_TOKEN(anon_sym_DASH); + if (lookahead == '-') ADVANCE(56); + if (lookahead == '>') ADVANCE(57); + END_STATE(); + case 61: + ACCEPT_TOKEN(sym_component_label); + if (lookahead == '\t' || + lookahead == ' ') ADVANCE(61); + if (lookahead != 0 && + lookahead != '\t' && + lookahead != '\n' && + lookahead != '\r' && + lookahead != '(' && + lookahead != ')' && + (lookahead < '+' || '-' < lookahead) && + lookahead != '[' && + lookahead != ']') ADVANCE(62); + END_STATE(); + case 62: + ACCEPT_TOKEN(sym_component_label); + if (lookahead != 0 && + lookahead != '\n' && + lookahead != '\r' && + lookahead != '(' && + lookahead != ')' && + (lookahead < '+' || '-' < lookahead) && + lookahead != '[' && + lookahead != ']') ADVANCE(62); + END_STATE(); + case 63: + ACCEPT_TOKEN(sym_text); + if (lookahead == '\t' || + lookahead == ' ') ADVANCE(63); + if (lookahead != 0 && + lookahead != '\t' && + lookahead != '\n' && + lookahead != '\r') ADVANCE(64); + END_STATE(); + case 64: + ACCEPT_TOKEN(sym_text); + if (lookahead != 0 && + lookahead != '\n' && + lookahead != '\r') ADVANCE(64); + END_STATE(); + case 65: + ACCEPT_TOKEN(aux_sym_real_number_token1); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(65); + END_STATE(); + case 66: + ACCEPT_TOKEN(aux_sym_real_number_token2); + if (lookahead == '.') ADVANCE(65); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(66); + END_STATE(); + case 67: + ACCEPT_TOKEN(aux_sym_real_number_token3); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(67); + END_STATE(); + case 68: + ACCEPT_TOKEN(aux_sym_stage_number_token1); + END_STATE(); + case 69: + ACCEPT_TOKEN(aux_sym_stage_number_token2); + END_STATE(); + case 70: + ACCEPT_TOKEN(aux_sym_stage_number_token3); + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(69); + END_STATE(); + case 71: + ACCEPT_TOKEN(aux_sym_stage_number_token4); + if (lookahead == 'I' || + lookahead == 'i') ADVANCE(70); + if (lookahead == 'V' || + lookahead == 'v') ADVANCE(68); + END_STATE(); + case 72: + ACCEPT_TOKEN(aux_sym_shape_label_token1); + END_STATE(); + case 73: + ACCEPT_TOKEN(aux_sym_shape_label_token2); + END_STATE(); + case 74: + ACCEPT_TOKEN(aux_sym_shape_label_token3); + END_STATE(); + case 75: + ACCEPT_TOKEN(aux_sym_shape_label_token4); + END_STATE(); + case 76: + ACCEPT_TOKEN(sym__note_keyword); + END_STATE(); + case 77: + ACCEPT_TOKEN(sym__group_keyword); + END_STATE(); + case 78: + ACCEPT_TOKEN(sym__inertia_keyword); + END_STATE(); + case 79: + ACCEPT_TOKEN(sym__evolution_keyword); + END_STATE(); + case 80: + ACCEPT_TOKEN(anon_sym_LF); + END_STATE(); + case 81: + ACCEPT_TOKEN(anon_sym_CR_LF); + END_STATE(); + case 82: + ACCEPT_TOKEN(anon_sym_CR); + if (lookahead == '\n') ADVANCE(81); + END_STATE(); + default: + return false; + } +} + +static const TSLexerMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 48}, + [2] = {.lex_state = 48}, + [3] = {.lex_state = 48}, + [4] = {.lex_state = 48}, + [5] = {.lex_state = 0}, + [6] = {.lex_state = 0}, + [7] = {.lex_state = 1}, + [8] = {.lex_state = 1}, + [9] = {.lex_state = 0}, + [10] = {.lex_state = 0}, + [11] = {.lex_state = 0}, + [12] = {.lex_state = 0}, + [13] = {.lex_state = 0}, + [14] = {.lex_state = 0}, + [15] = {.lex_state = 0}, + [16] = {.lex_state = 0}, + [17] = {.lex_state = 0}, + [18] = {.lex_state = 0}, + [19] = {.lex_state = 0}, + [20] = {.lex_state = 1}, + [21] = {.lex_state = 0}, + [22] = {.lex_state = 0}, + [23] = {.lex_state = 0}, + [24] = {.lex_state = 0}, + [25] = {.lex_state = 0}, + [26] = {.lex_state = 0}, + [27] = {.lex_state = 0}, + [28] = {.lex_state = 0}, + [29] = {.lex_state = 2}, + [30] = {.lex_state = 0}, + [31] = {.lex_state = 0}, + [32] = {.lex_state = 0}, + [33] = {.lex_state = 0}, + [34] = {.lex_state = 48}, + [35] = {.lex_state = 48}, + [36] = {.lex_state = 0}, + [37] = {.lex_state = 48}, + [38] = {.lex_state = 8}, + [39] = {.lex_state = 48}, + [40] = {.lex_state = 0}, + [41] = {.lex_state = 48}, + [42] = {.lex_state = 0}, + [43] = {.lex_state = 0}, + [44] = {.lex_state = 0}, + [45] = {.lex_state = 8}, + [46] = {.lex_state = 0}, + [47] = {.lex_state = 48}, + [48] = {.lex_state = 0}, + [49] = {.lex_state = 0}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [STATE(0)] = { + [ts_builtin_sym_end] = ACTIONS(1), + [anon_sym_LBRACK] = ACTIONS(1), + [anon_sym_RBRACK] = ACTIONS(1), + [anon_sym_COMMA] = ACTIONS(1), + [anon_sym_LPAREN] = ACTIONS(1), + [anon_sym_RPAREN] = ACTIONS(1), + [anon_sym_DASH_DASH] = ACTIONS(1), + [anon_sym_DASH_GT] = ACTIONS(1), + [anon_sym_PLUS] = ACTIONS(1), + [anon_sym_DASH] = ACTIONS(1), + [aux_sym_real_number_token1] = ACTIONS(1), + [aux_sym_real_number_token2] = ACTIONS(1), + [aux_sym_real_number_token3] = ACTIONS(1), + [aux_sym_stage_number_token1] = ACTIONS(1), + [aux_sym_stage_number_token2] = ACTIONS(1), + [aux_sym_stage_number_token3] = ACTIONS(1), + [aux_sym_stage_number_token4] = ACTIONS(1), + [aux_sym_shape_label_token1] = ACTIONS(1), + [aux_sym_shape_label_token2] = ACTIONS(1), + [aux_sym_shape_label_token3] = ACTIONS(1), + [aux_sym_shape_label_token4] = ACTIONS(1), + [sym__note_keyword] = ACTIONS(1), + [sym__group_keyword] = ACTIONS(1), + [sym__inertia_keyword] = ACTIONS(1), + [sym__evolution_keyword] = ACTIONS(1), + [anon_sym_LF] = ACTIONS(1), + [anon_sym_CR_LF] = ACTIONS(1), + [anon_sym_CR] = ACTIONS(1), + }, + [STATE(1)] = { + [sym_source_file] = STATE(49), + [sym_entity] = STATE(15), + [sym_component] = STATE(25), + [sym_dependency] = STATE(25), + [sym_note] = STATE(25), + [sym_stage] = STATE(25), + [sym_group] = STATE(25), + [sym_inertia] = STATE(25), + [sym_evolution] = STATE(25), + [sym__line_ending] = STATE(2), + [aux_sym_source_file_repeat1] = STATE(2), + [ts_builtin_sym_end] = ACTIONS(3), + [anon_sym_LBRACK] = ACTIONS(5), + [sym_component_label] = ACTIONS(7), + [sym__note_keyword] = ACTIONS(9), + [sym__group_keyword] = ACTIONS(11), + [sym__inertia_keyword] = ACTIONS(13), + [sym__evolution_keyword] = ACTIONS(15), + [anon_sym_LF] = ACTIONS(17), + [anon_sym_CR_LF] = ACTIONS(17), + [anon_sym_CR] = ACTIONS(17), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 11, + ACTIONS(5), 1, + anon_sym_LBRACK, + ACTIONS(7), 1, + sym_component_label, + ACTIONS(9), 1, + sym__note_keyword, + ACTIONS(11), 1, + sym__group_keyword, + ACTIONS(13), 1, + sym__inertia_keyword, + ACTIONS(15), 1, + sym__evolution_keyword, + ACTIONS(19), 1, + ts_builtin_sym_end, + STATE(15), 1, + sym_entity, + STATE(3), 2, + sym__line_ending, + aux_sym_source_file_repeat1, + ACTIONS(21), 3, + anon_sym_LF, + anon_sym_CR_LF, + anon_sym_CR, + STATE(25), 7, + sym_component, + sym_dependency, + sym_note, + sym_stage, + sym_group, + sym_inertia, + sym_evolution, + [43] = 11, + ACTIONS(23), 1, + ts_builtin_sym_end, + ACTIONS(25), 1, + anon_sym_LBRACK, + ACTIONS(28), 1, + sym_component_label, + ACTIONS(31), 1, + sym__note_keyword, + ACTIONS(34), 1, + sym__group_keyword, + ACTIONS(37), 1, + sym__inertia_keyword, + ACTIONS(40), 1, + sym__evolution_keyword, + STATE(15), 1, + sym_entity, + STATE(3), 2, + sym__line_ending, + aux_sym_source_file_repeat1, + ACTIONS(43), 3, + anon_sym_LF, + anon_sym_CR_LF, + anon_sym_CR, + STATE(25), 7, + sym_component, + sym_dependency, + sym_note, + sym_stage, + sym_group, + sym_inertia, + sym_evolution, + [86] = 2, + ACTIONS(23), 2, + ts_builtin_sym_end, + sym_component_label, + ACTIONS(46), 8, + anon_sym_LBRACK, + sym__note_keyword, + sym__group_keyword, + sym__inertia_keyword, + sym__evolution_keyword, + anon_sym_LF, + anon_sym_CR_LF, + anon_sym_CR, + [101] = 4, + ACTIONS(48), 1, + anon_sym_COMMA, + ACTIONS(52), 1, + anon_sym_CR, + STATE(11), 1, + aux_sym_group_repeat1, + ACTIONS(50), 2, + anon_sym_LF, + anon_sym_CR_LF, + [115] = 3, + STATE(43), 1, + sym_stage_number, + ACTIONS(54), 2, + aux_sym_stage_number_token1, + aux_sym_stage_number_token2, + ACTIONS(56), 2, + aux_sym_stage_number_token3, + aux_sym_stage_number_token4, + [127] = 4, + ACTIONS(58), 1, + anon_sym_LBRACK, + ACTIONS(62), 1, + anon_sym_CR, + STATE(27), 1, + sym_shape, + ACTIONS(60), 2, + anon_sym_LF, + anon_sym_CR_LF, + [141] = 4, + ACTIONS(64), 1, + anon_sym_LPAREN, + STATE(7), 1, + sym_position, + STATE(34), 1, + sym_dependency_type, + ACTIONS(66), 2, + anon_sym_DASH_DASH, + anon_sym_DASH_GT, + [155] = 2, + ACTIONS(70), 1, + anon_sym_CR, + ACTIONS(68), 4, + anon_sym_COMMA, + anon_sym_RPAREN, + anon_sym_LF, + anon_sym_CR_LF, + [165] = 2, + STATE(40), 1, + sym_shape_label, + ACTIONS(72), 4, + aux_sym_shape_label_token1, + aux_sym_shape_label_token2, + aux_sym_shape_label_token3, + aux_sym_shape_label_token4, + [175] = 4, + ACTIONS(48), 1, + anon_sym_COMMA, + ACTIONS(76), 1, + anon_sym_CR, + STATE(12), 1, + aux_sym_group_repeat1, + ACTIONS(74), 2, + anon_sym_LF, + anon_sym_CR_LF, + [189] = 4, + ACTIONS(78), 1, + anon_sym_COMMA, + ACTIONS(83), 1, + anon_sym_CR, + STATE(12), 1, + aux_sym_group_repeat1, + ACTIONS(81), 2, + anon_sym_LF, + anon_sym_CR_LF, + [203] = 3, + ACTIONS(87), 1, + aux_sym_real_number_token2, + STATE(23), 1, + sym_real_number, + ACTIONS(85), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [214] = 3, + ACTIONS(87), 1, + aux_sym_real_number_token2, + STATE(48), 1, + sym_real_number, + ACTIONS(85), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [225] = 3, + ACTIONS(91), 1, + anon_sym_CR, + STATE(4), 1, + sym__line_ending, + ACTIONS(89), 2, + anon_sym_LF, + anon_sym_CR_LF, + [236] = 3, + ACTIONS(87), 1, + aux_sym_real_number_token2, + STATE(33), 1, + sym_real_number, + ACTIONS(85), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [247] = 3, + ACTIONS(87), 1, + aux_sym_real_number_token2, + STATE(28), 1, + sym_real_number, + ACTIONS(85), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [258] = 3, + ACTIONS(87), 1, + aux_sym_real_number_token2, + STATE(44), 1, + sym_real_number, + ACTIONS(85), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [269] = 2, + ACTIONS(95), 1, + anon_sym_CR, + ACTIONS(93), 3, + anon_sym_COMMA, + anon_sym_LF, + anon_sym_CR_LF, + [278] = 2, + ACTIONS(99), 1, + anon_sym_CR, + ACTIONS(97), 3, + anon_sym_LBRACK, + anon_sym_LF, + anon_sym_CR_LF, + [287] = 3, + ACTIONS(87), 1, + aux_sym_real_number_token2, + STATE(46), 1, + sym_real_number, + ACTIONS(85), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [298] = 2, + ACTIONS(103), 1, + anon_sym_CR, + ACTIONS(101), 2, + anon_sym_LF, + anon_sym_CR_LF, + [306] = 2, + ACTIONS(107), 1, + anon_sym_CR, + ACTIONS(105), 2, + anon_sym_LF, + anon_sym_CR_LF, + [314] = 2, + ACTIONS(111), 1, + aux_sym_real_number_token2, + ACTIONS(109), 2, + aux_sym_real_number_token1, + aux_sym_real_number_token3, + [322] = 2, + ACTIONS(115), 1, + anon_sym_CR, + ACTIONS(113), 2, + anon_sym_LF, + anon_sym_CR_LF, + [330] = 2, + ACTIONS(119), 1, + anon_sym_CR, + ACTIONS(117), 2, + anon_sym_LF, + anon_sym_CR_LF, + [338] = 2, + ACTIONS(123), 1, + anon_sym_CR, + ACTIONS(121), 2, + anon_sym_LF, + anon_sym_CR_LF, + [346] = 2, + ACTIONS(127), 1, + anon_sym_CR, + ACTIONS(125), 2, + anon_sym_LF, + anon_sym_CR_LF, + [354] = 2, + STATE(17), 1, + sym_sign, + ACTIONS(129), 2, + anon_sym_PLUS, + anon_sym_DASH, + [362] = 2, + ACTIONS(133), 1, + anon_sym_CR, + ACTIONS(131), 2, + anon_sym_LF, + anon_sym_CR_LF, + [370] = 2, + ACTIONS(137), 1, + anon_sym_CR, + ACTIONS(135), 2, + anon_sym_LF, + anon_sym_CR_LF, + [378] = 2, + ACTIONS(139), 1, + anon_sym_LPAREN, + STATE(38), 1, + sym_position, + [385] = 1, + ACTIONS(141), 1, + anon_sym_COMMA, + [389] = 1, + ACTIONS(143), 1, + sym_component_label, + [393] = 1, + ACTIONS(145), 1, + sym_component_label, + [397] = 1, + ACTIONS(147), 1, + anon_sym_RBRACK, + [401] = 1, + ACTIONS(149), 1, + sym_component_label, + [405] = 1, + ACTIONS(151), 1, + sym_text, + [409] = 1, + ACTIONS(153), 1, + sym_component_label, + [413] = 1, + ACTIONS(155), 1, + anon_sym_RBRACK, + [417] = 1, + ACTIONS(157), 1, + sym_component_label, + [421] = 1, + ACTIONS(159), 1, + anon_sym_RBRACK, + [425] = 1, + ACTIONS(161), 1, + anon_sym_RBRACK, + [429] = 1, + ACTIONS(163), 1, + anon_sym_RPAREN, + [433] = 1, + ACTIONS(97), 1, + sym_text, + [437] = 1, + ACTIONS(165), 1, + anon_sym_RPAREN, + [441] = 1, + ACTIONS(167), 1, + sym_component_label, + [445] = 1, + ACTIONS(169), 1, + anon_sym_COMMA, + [449] = 1, + ACTIONS(171), 1, + ts_builtin_sym_end, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(2)] = 0, + [SMALL_STATE(3)] = 43, + [SMALL_STATE(4)] = 86, + [SMALL_STATE(5)] = 101, + [SMALL_STATE(6)] = 115, + [SMALL_STATE(7)] = 127, + [SMALL_STATE(8)] = 141, + [SMALL_STATE(9)] = 155, + [SMALL_STATE(10)] = 165, + [SMALL_STATE(11)] = 175, + [SMALL_STATE(12)] = 189, + [SMALL_STATE(13)] = 203, + [SMALL_STATE(14)] = 214, + [SMALL_STATE(15)] = 225, + [SMALL_STATE(16)] = 236, + [SMALL_STATE(17)] = 247, + [SMALL_STATE(18)] = 258, + [SMALL_STATE(19)] = 269, + [SMALL_STATE(20)] = 278, + [SMALL_STATE(21)] = 287, + [SMALL_STATE(22)] = 298, + [SMALL_STATE(23)] = 306, + [SMALL_STATE(24)] = 314, + [SMALL_STATE(25)] = 322, + [SMALL_STATE(26)] = 330, + [SMALL_STATE(27)] = 338, + [SMALL_STATE(28)] = 346, + [SMALL_STATE(29)] = 354, + [SMALL_STATE(30)] = 362, + [SMALL_STATE(31)] = 370, + [SMALL_STATE(32)] = 378, + [SMALL_STATE(33)] = 385, + [SMALL_STATE(34)] = 389, + [SMALL_STATE(35)] = 393, + [SMALL_STATE(36)] = 397, + [SMALL_STATE(37)] = 401, + [SMALL_STATE(38)] = 405, + [SMALL_STATE(39)] = 409, + [SMALL_STATE(40)] = 413, + [SMALL_STATE(41)] = 417, + [SMALL_STATE(42)] = 421, + [SMALL_STATE(43)] = 425, + [SMALL_STATE(44)] = 429, + [SMALL_STATE(45)] = 433, + [SMALL_STATE(46)] = 437, + [SMALL_STATE(47)] = 441, + [SMALL_STATE(48)] = 445, + [SMALL_STATE(49)] = 449, +}; + +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(6), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), + [9] = {.entry = {.count = 1, .reusable = false}}, SHIFT(32), + [11] = {.entry = {.count = 1, .reusable = false}}, SHIFT(37), + [13] = {.entry = {.count = 1, .reusable = false}}, SHIFT(41), + [15] = {.entry = {.count = 1, .reusable = false}}, SHIFT(47), + [17] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2), + [19] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0), + [21] = {.entry = {.count = 1, .reusable = false}}, SHIFT(3), + [23] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), + [25] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(6), + [28] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(8), + [31] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(32), + [34] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(37), + [37] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(41), + [40] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(47), + [43] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(3), + [46] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), + [48] = {.entry = {.count = 1, .reusable = true}}, SHIFT(35), + [50] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_group, 2, 0, 2), + [52] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_group, 2, 0, 2), + [54] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36), + [56] = {.entry = {.count = 1, .reusable = false}}, SHIFT(36), + [58] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), + [60] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_component, 2, 0, 1), + [62] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_component, 2, 0, 1), + [64] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), + [66] = {.entry = {.count = 1, .reusable = true}}, SHIFT(39), + [68] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_real_number, 1, 0, 0), + [70] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_real_number, 1, 0, 0), + [72] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42), + [74] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_group, 3, 0, 6), + [76] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_group, 3, 0, 6), + [78] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_group_repeat1, 2, 0, 8), SHIFT_REPEAT(35), + [81] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_group_repeat1, 2, 0, 8), + [83] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_group_repeat1, 2, 0, 8), + [85] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), + [87] = {.entry = {.count = 1, .reusable = false}}, SHIFT(9), + [89] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [91] = {.entry = {.count = 1, .reusable = false}}, SHIFT(4), + [93] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_group_repeat1, 2, 0, 2), + [95] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_group_repeat1, 2, 0, 2), + [97] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_position, 5, 0, 10), + [99] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_position, 5, 0, 10), + [101] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_note, 3, 0, 5), + [103] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_note, 3, 0, 5), + [105] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_stage, 4, 0, 7), + [107] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_stage, 4, 0, 7), + [109] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_sign, 1, 0, 0), + [111] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_sign, 1, 0, 0), + [113] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_entity, 1, 0, 0), + [115] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_entity, 1, 0, 0), + [117] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_dependency, 3, 0, 4), + [119] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_dependency, 3, 0, 4), + [121] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_component, 3, 0, 3), + [123] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_component, 3, 0, 3), + [125] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_evolution, 4, 0, 9), + [127] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_evolution, 4, 0, 9), + [129] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), + [131] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_inertia, 2, 0, 2), + [133] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_inertia, 2, 0, 2), + [135] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_shape, 3, 0, 0), + [137] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_shape, 3, 0, 0), + [139] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), + [141] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), + [143] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26), + [145] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), + [147] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_stage_number, 1, 0, 0), + [149] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), + [151] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), + [153] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_dependency_type, 1, 0, 0), + [155] = {.entry = {.count = 1, .reusable = true}}, SHIFT(31), + [157] = {.entry = {.count = 1, .reusable = true}}, SHIFT(30), + [159] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_shape_label, 1, 0, 0), + [161] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [163] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [165] = {.entry = {.count = 1, .reusable = true}}, SHIFT(45), + [167] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), + [169] = {.entry = {.count = 1, .reusable = true}}, SHIFT(21), + [171] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), +}; + +#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_wmap(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 = "wmap", + .max_reserved_word_set_size = 0, + .metadata = { + .major_version = 1, + .minor_version = 0, + .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 <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +// 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 <assert.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#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 <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#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_ |