From 51def200ab2408a6f6caa12914bd378ad9d564b8 Mon Sep 17 00:00:00 2001 From: Peter Hart Date: Fri, 2 Sep 2022 23:36:25 -0400 Subject: [PATCH] initial checking --- .gitignore | 13 + Cargo.toml | 26 + binding.gyp | 19 + bindings/node/binding.cc | 28 + bindings/node/index.js | 19 + bindings/rust/build.rs | 40 + bindings/rust/lib.rs | 52 ++ grammar.js | 63 ++ package.json | 17 + src/grammar.json | 320 +++++++ src/node-types.json | 185 ++++ src/parser.c | 1395 ++++++++++++++++++++++++++++ src/tree_sitter/parser.h | 224 +++++ test/corpus/import statements.txt | 47 + test/corpus/package definition.txt | 20 + test/corpus/shebang.txt | 33 + test/corpus/statements.txt | 90 ++ 17 files changed, 2591 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 binding.gyp create mode 100644 bindings/node/binding.cc create mode 100644 bindings/node/index.js create mode 100644 bindings/rust/build.rs create mode 100644 bindings/rust/lib.rs create mode 100644 grammar.js create mode 100644 package.json create mode 100644 src/grammar.json create mode 100644 src/node-types.json create mode 100644 src/parser.c create mode 100644 src/tree_sitter/parser.h create mode 100644 test/corpus/import statements.txt create mode 100644 test/corpus/package definition.txt create mode 100644 test/corpus/shebang.txt create mode 100644 test/corpus/statements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3ad95b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +Cargo.lock +node_modules +build +*.log +package-lock.json +target +*.a +*.dylib +*.so +*.o +bindings/c/*.h +bindings/c/tree-sitter-*.pc +.build/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ebf5e47 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "tree-sitter-Groovy" +description = "Groovy grammar for the tree-sitter parsing library" +version = "0.0.1" +keywords = ["incremental", "parsing", "Groovy"] +categories = ["parsing", "text-editors"] +repository = "https://github.com/tree-sitter/tree-sitter-Groovy" +edition = "2018" +license = "MIT" + +build = "bindings/rust/build.rs" +include = [ + "bindings/rust/*", + "grammar.js", + "queries/*", + "src/*", +] + +[lib] +path = "bindings/rust/lib.rs" + +[dependencies] +tree-sitter = "~0.20.3" + +[build-dependencies] +cc = "1.0" diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..59a4517 --- /dev/null +++ b/binding.gyp @@ -0,0 +1,19 @@ +{ + "targets": [ + { + "target_name": "tree_sitter_Groovy_binding", + "include_dirs": [ + " +#include "nan.h" + +using namespace v8; + +extern "C" TSLanguage * tree_sitter_Groovy(); + +namespace { + +NAN_METHOD(New) {} + +void Init(Local exports, Local module) { + Local tpl = Nan::New(New); + tpl->SetClassName(Nan::New("Language").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); + Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); + Nan::SetInternalFieldPointer(instance, 0, tree_sitter_Groovy()); + + Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("Groovy").ToLocalChecked()); + Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); +} + +NODE_MODULE(tree_sitter_Groovy_binding, Init) + +} // namespace diff --git a/bindings/node/index.js b/bindings/node/index.js new file mode 100644 index 0000000..8eaa78e --- /dev/null +++ b/bindings/node/index.js @@ -0,0 +1,19 @@ +try { + module.exports = require("../../build/Release/tree_sitter_Groovy_binding"); +} catch (error1) { + if (error1.code !== 'MODULE_NOT_FOUND') { + throw error1; + } + try { + module.exports = require("../../build/Debug/tree_sitter_Groovy_binding"); + } catch (error2) { + if (error2.code !== 'MODULE_NOT_FOUND') { + throw error2; + } + throw error1 + } +} + +try { + module.exports.nodeTypeInfo = require("../../src/node-types.json"); +} catch (_) {} diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs new file mode 100644 index 0000000..c6061f0 --- /dev/null +++ b/bindings/rust/build.rs @@ -0,0 +1,40 @@ +fn main() { + let src_dir = std::path::Path::new("src"); + + let mut c_config = cc::Build::new(); + c_config.include(&src_dir); + c_config + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable") + .flag_if_supported("-Wno-trigraphs"); + let parser_path = src_dir.join("parser.c"); + c_config.file(&parser_path); + + // If your language uses an external scanner written in C, + // then include this block of code: + + /* + let scanner_path = src_dir.join("scanner.c"); + c_config.file(&scanner_path); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + */ + + c_config.compile("parser"); + println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); + + // If your language uses an external scanner written in C++, + // then include this block of code: + + /* + let mut cpp_config = cc::Build::new(); + cpp_config.cpp(true); + cpp_config.include(&src_dir); + cpp_config + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable"); + let scanner_path = src_dir.join("scanner.cc"); + cpp_config.file(&scanner_path); + cpp_config.compile("scanner"); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + */ +} diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs new file mode 100644 index 0000000..2817c48 --- /dev/null +++ b/bindings/rust/lib.rs @@ -0,0 +1,52 @@ +//! This crate provides Groovy language support for the [tree-sitter][] parsing library. +//! +//! Typically, you will use the [language][language func] function to add this language to a +//! tree-sitter [Parser][], and then use the parser to parse some code: +//! +//! ``` +//! let code = ""; +//! let mut parser = tree_sitter::Parser::new(); +//! parser.set_language(tree_sitter_Groovy::language()).expect("Error loading Groovy grammar"); +//! let tree = parser.parse(code, None).unwrap(); +//! ``` +//! +//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +//! [language func]: fn.language.html +//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html +//! [tree-sitter]: https://tree-sitter.github.io/ + +use tree_sitter::Language; + +extern "C" { + fn tree_sitter_Groovy() -> Language; +} + +/// Get the tree-sitter [Language][] for this grammar. +/// +/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +pub fn language() -> Language { + unsafe { tree_sitter_Groovy() } +} + +/// The content of the [`node-types.json`][] file for this grammar. +/// +/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types +pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); + +// Uncomment these to include any queries that this grammar contains + +// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); +// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); +// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); +// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); + +#[cfg(test)] +mod tests { + #[test] + fn test_can_load_grammar() { + let mut parser = tree_sitter::Parser::new(); + parser + .set_language(super::language()) + .expect("Error loading Groovy language"); + } +} diff --git a/grammar.js b/grammar.js new file mode 100644 index 0000000..011da62 --- /dev/null +++ b/grammar.js @@ -0,0 +1,63 @@ +module.exports = grammar({ + name: 'Groovy', + + rules: { + // TODO: add the actual grammar rules + source_file: $ => seq( + optional($._shebang_comment), + optional(seq($.package_definition, repeat($._nl_semicolon))), + repeat( + choice( + seq( + $.import_statement, + repeat1($._nl_semicolon) + ), + seq( + $.script_part, + repeat1($._nl_semicolon) + ) + ) + ), + optional($.script_part) + ), + import_statement: $ => seq( + 'import', + optional('static'), + field('name', + seq( + $.identifier, + repeat(seq('.', $.identifier)), + optional(seq('.', '*') + ) + ) + ) + ), + _shebang_comment: $ => token.immediate(/#!.*\n/), + package_definition: $ => seq( + 'package', + field('name', seq( + $.identifier, + repeat(seq('.', $.identifier)))) + ), + script_part: $ => choice( + $.statement, + $.method_declaration + ), + expression: $ => choice( + $.path_expression + ), + path_expression: $ => seq( + repeat( + seq($.identifier, '.') + ), + $.identifier + ), + identifier: $ => /[A-Za-z_][A-Za-z_0-9]*/, + statement: $ => choice( + $.expression + ), + method_declaration: $ => seq('def', field('name', $.identifier)), + _nl_semicolon: $ => choice('\n', ';'), + word: $ => $.identifier + } +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..c5be90a --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "tree-sitter-groovy", + "version": "0.0.1", + "description": "Groovy tree-sitter grammar", + "main": "bindings/node", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Peter Hart", + "license": "ISC", + "dependencies": { + "nan": "^2.16.0" + }, + "devDependencies": { + "tree-sitter-cli": "^0.20.7" + } +} diff --git a/src/grammar.json b/src/grammar.json new file mode 100644 index 0000000..5dc5428 --- /dev/null +++ b/src/grammar.json @@ -0,0 +1,320 @@ +{ + "name": "Groovy", + "rules": { + "source_file": { + "type": "SEQ", + "members": [ + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_shebang_comment" + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "package_definition" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "_nl_semicolon" + } + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "import_statement" + }, + { + "type": "REPEAT1", + "content": { + "type": "SYMBOL", + "name": "_nl_semicolon" + } + } + ] + }, + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "script_part" + }, + { + "type": "REPEAT1", + "content": { + "type": "SYMBOL", + "name": "_nl_semicolon" + } + } + ] + } + ] + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "script_part" + }, + { + "type": "BLANK" + } + ] + } + ] + }, + "import_statement": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "import" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "static" + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "FIELD", + "name": "name", + "content": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "." + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "." + }, + { + "type": "STRING", + "value": "*" + } + ] + }, + { + "type": "BLANK" + } + ] + } + ] + } + } + ] + }, + "_shebang_comment": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "PATTERN", + "value": "#!.*\\n" + } + }, + "package_definition": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "package" + }, + { + "type": "FIELD", + "name": "name", + "content": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "." + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + } + } + ] + } + } + ] + }, + "script_part": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "statement" + }, + { + "type": "SYMBOL", + "name": "method_declaration" + } + ] + }, + "expression": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "path_expression" + } + ] + }, + "path_expression": { + "type": "SEQ", + "members": [ + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "STRING", + "value": "." + } + ] + } + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + "identifier": { + "type": "PATTERN", + "value": "[A-Za-z_][A-Za-z_0-9]*" + }, + "statement": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "expression" + } + ] + }, + "method_declaration": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "def" + }, + { + "type": "FIELD", + "name": "name", + "content": { + "type": "SYMBOL", + "name": "identifier" + } + } + ] + }, + "_nl_semicolon": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "\n" + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "word": { + "type": "SYMBOL", + "name": "identifier" + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "\\s" + } + ], + "conflicts": [], + "precedences": [], + "externals": [], + "inline": [], + "supertypes": [] +} + diff --git a/src/node-types.json b/src/node-types.json new file mode 100644 index 0000000..a85ed09 --- /dev/null +++ b/src/node-types.json @@ -0,0 +1,185 @@ +[ + { + "type": "expression", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "path_expression", + "named": true + } + ] + } + }, + { + "type": "import_statement", + "named": true, + "fields": { + "name": { + "multiple": true, + "required": true, + "types": [ + { + "type": "*", + "named": false + }, + { + "type": ".", + "named": false + }, + { + "type": "identifier", + "named": true + } + ] + } + } + }, + { + "type": "method_declaration", + "named": true, + "fields": { + "name": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + } + } + }, + { + "type": "package_definition", + "named": true, + "fields": { + "name": { + "multiple": true, + "required": true, + "types": [ + { + "type": ".", + "named": false + }, + { + "type": "identifier", + "named": true + } + ] + } + } + }, + { + "type": "path_expression", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "script_part", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "method_declaration", + "named": true + }, + { + "type": "statement", + "named": true + } + ] + } + }, + { + "type": "source_file", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "import_statement", + "named": true + }, + { + "type": "package_definition", + "named": true + }, + { + "type": "script_part", + "named": true + } + ] + } + }, + { + "type": "statement", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "expression", + "named": true + } + ] + } + }, + { + "type": "\n", + "named": false + }, + { + "type": "*", + "named": false + }, + { + "type": ".", + "named": false + }, + { + "type": ";", + "named": false + }, + { + "type": "def", + "named": false + }, + { + "type": "identifier", + "named": true + }, + { + "type": "import", + "named": false + }, + { + "type": "package", + "named": false + }, + { + "type": "static", + "named": false + } +] \ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..19486d3 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,1395 @@ +#include + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#define LANGUAGE_VERSION 14 +#define STATE_COUNT 52 +#define LARGE_STATE_COUNT 7 +#define SYMBOL_COUNT 24 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 11 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 1 +#define MAX_ALIAS_SEQUENCE_LENGTH 6 +#define PRODUCTION_ID_COUNT 9 + +enum { + anon_sym_import = 1, + anon_sym_static = 2, + anon_sym_DOT = 3, + anon_sym_STAR = 4, + sym__shebang_comment = 5, + anon_sym_package = 6, + sym_identifier = 7, + anon_sym_def = 8, + anon_sym_LF = 9, + anon_sym_SEMI = 10, + sym_source_file = 11, + sym_import_statement = 12, + sym_package_definition = 13, + sym_script_part = 14, + sym_expression = 15, + sym_path_expression = 16, + sym_statement = 17, + sym_method_declaration = 18, + sym__nl_semicolon = 19, + aux_sym_source_file_repeat1 = 20, + aux_sym_source_file_repeat2 = 21, + aux_sym_import_statement_repeat1 = 22, + aux_sym_path_expression_repeat1 = 23, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [anon_sym_import] = "import", + [anon_sym_static] = "static", + [anon_sym_DOT] = ".", + [anon_sym_STAR] = "*", + [sym__shebang_comment] = "_shebang_comment", + [anon_sym_package] = "package", + [sym_identifier] = "identifier", + [anon_sym_def] = "def", + [anon_sym_LF] = "\n", + [anon_sym_SEMI] = ";", + [sym_source_file] = "source_file", + [sym_import_statement] = "import_statement", + [sym_package_definition] = "package_definition", + [sym_script_part] = "script_part", + [sym_expression] = "expression", + [sym_path_expression] = "path_expression", + [sym_statement] = "statement", + [sym_method_declaration] = "method_declaration", + [sym__nl_semicolon] = "_nl_semicolon", + [aux_sym_source_file_repeat1] = "source_file_repeat1", + [aux_sym_source_file_repeat2] = "source_file_repeat2", + [aux_sym_import_statement_repeat1] = "import_statement_repeat1", + [aux_sym_path_expression_repeat1] = "path_expression_repeat1", +}; + +static const TSSymbol ts_symbol_map[] = { + [ts_builtin_sym_end] = ts_builtin_sym_end, + [anon_sym_import] = anon_sym_import, + [anon_sym_static] = anon_sym_static, + [anon_sym_DOT] = anon_sym_DOT, + [anon_sym_STAR] = anon_sym_STAR, + [sym__shebang_comment] = sym__shebang_comment, + [anon_sym_package] = anon_sym_package, + [sym_identifier] = sym_identifier, + [anon_sym_def] = anon_sym_def, + [anon_sym_LF] = anon_sym_LF, + [anon_sym_SEMI] = anon_sym_SEMI, + [sym_source_file] = sym_source_file, + [sym_import_statement] = sym_import_statement, + [sym_package_definition] = sym_package_definition, + [sym_script_part] = sym_script_part, + [sym_expression] = sym_expression, + [sym_path_expression] = sym_path_expression, + [sym_statement] = sym_statement, + [sym_method_declaration] = sym_method_declaration, + [sym__nl_semicolon] = sym__nl_semicolon, + [aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1, + [aux_sym_source_file_repeat2] = aux_sym_source_file_repeat2, + [aux_sym_import_statement_repeat1] = aux_sym_import_statement_repeat1, + [aux_sym_path_expression_repeat1] = aux_sym_path_expression_repeat1, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [anon_sym_import] = { + .visible = true, + .named = false, + }, + [anon_sym_static] = { + .visible = true, + .named = false, + }, + [anon_sym_DOT] = { + .visible = true, + .named = false, + }, + [anon_sym_STAR] = { + .visible = true, + .named = false, + }, + [sym__shebang_comment] = { + .visible = false, + .named = true, + }, + [anon_sym_package] = { + .visible = true, + .named = false, + }, + [sym_identifier] = { + .visible = true, + .named = true, + }, + [anon_sym_def] = { + .visible = true, + .named = false, + }, + [anon_sym_LF] = { + .visible = true, + .named = false, + }, + [anon_sym_SEMI] = { + .visible = true, + .named = false, + }, + [sym_source_file] = { + .visible = true, + .named = true, + }, + [sym_import_statement] = { + .visible = true, + .named = true, + }, + [sym_package_definition] = { + .visible = true, + .named = true, + }, + [sym_script_part] = { + .visible = true, + .named = true, + }, + [sym_expression] = { + .visible = true, + .named = true, + }, + [sym_path_expression] = { + .visible = true, + .named = true, + }, + [sym_statement] = { + .visible = true, + .named = true, + }, + [sym_method_declaration] = { + .visible = true, + .named = true, + }, + [sym__nl_semicolon] = { + .visible = false, + .named = true, + }, + [aux_sym_source_file_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_source_file_repeat2] = { + .visible = false, + .named = false, + }, + [aux_sym_import_statement_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_path_expression_repeat1] = { + .visible = false, + .named = false, + }, +}; + +enum { + field_name = 1, +}; + +static const char * const ts_field_names[] = { + [0] = NULL, + [field_name] = "name", +}; + +static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { + [1] = {.index = 0, .length = 1}, + [2] = {.index = 1, .length = 1}, + [3] = {.index = 2, .length = 2}, + [4] = {.index = 4, .length = 2}, + [5] = {.index = 6, .length = 3}, + [6] = {.index = 9, .length = 3}, + [7] = {.index = 12, .length = 4}, + [8] = {.index = 16, .length = 4}, +}; + +static const TSFieldMapEntry ts_field_map_entries[] = { + [0] = + {field_name, 1}, + [1] = + {field_name, 2}, + [2] = + {field_name, 1}, + {field_name, 2}, + [4] = + {field_name, 2}, + {field_name, 3}, + [6] = + {field_name, 1}, + {field_name, 2}, + {field_name, 3}, + [9] = + {field_name, 2}, + {field_name, 3}, + {field_name, 4}, + [12] = + {field_name, 1}, + {field_name, 2}, + {field_name, 3}, + {field_name, 4}, + [16] = + {field_name, 2}, + {field_name, 3}, + {field_name, 4}, + {field_name, 5}, +}; + +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, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(10); + if (lookahead == '#') ADVANCE(2); + if (lookahead == '*') ADVANCE(14); + if (lookahead == '.') ADVANCE(13); + if (lookahead == ';') ADVANCE(38); + if (lookahead == 'd') ADVANCE(22); + if (lookahead == 'i') ADVANCE(28); + if (lookahead == 'p') ADVANCE(17); + if (lookahead == 's') ADVANCE(34); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(7) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 1: + if (lookahead == '\n') ADVANCE(15); + if (lookahead != 0) ADVANCE(1); + END_STATE(); + case 2: + if (lookahead == '!') ADVANCE(1); + END_STATE(); + case 3: + if (lookahead == '*') ADVANCE(14); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(3) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 4: + if (lookahead == 's') ADVANCE(34); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(4) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 5: + if (eof) ADVANCE(10); + if (lookahead == '\n') ADVANCE(37); + if (lookahead == '.') ADVANCE(13); + if (lookahead == ';') ADVANCE(38); + if (lookahead == 'd') ADVANCE(22); + if (lookahead == 'i') ADVANCE(28); + if (lookahead == '\t' || + lookahead == '\r' || + lookahead == ' ') SKIP(5) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 6: + if (eof) ADVANCE(10); + if (lookahead == '#') ADVANCE(2); + if (lookahead == 'd') ADVANCE(22); + if (lookahead == 'i') ADVANCE(28); + if (lookahead == 'p') ADVANCE(17); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(8) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 7: + if (eof) ADVANCE(10); + if (lookahead == '*') ADVANCE(14); + if (lookahead == '.') ADVANCE(13); + if (lookahead == ';') ADVANCE(38); + if (lookahead == 'd') ADVANCE(22); + if (lookahead == 'i') ADVANCE(28); + if (lookahead == 'p') ADVANCE(17); + if (lookahead == 's') ADVANCE(34); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(7) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 8: + if (eof) ADVANCE(10); + if (lookahead == 'd') ADVANCE(22); + if (lookahead == 'i') ADVANCE(28); + if (lookahead == 'p') ADVANCE(17); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(8) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 9: + if (eof) ADVANCE(10); + if (lookahead == 'd') ADVANCE(22); + if (lookahead == 'i') ADVANCE(28); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(9) + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 10: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 11: + ACCEPT_TOKEN(anon_sym_import); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 12: + ACCEPT_TOKEN(anon_sym_static); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 13: + ACCEPT_TOKEN(anon_sym_DOT); + END_STATE(); + case 14: + ACCEPT_TOKEN(anon_sym_STAR); + END_STATE(); + case 15: + ACCEPT_TOKEN(sym__shebang_comment); + END_STATE(); + case 16: + ACCEPT_TOKEN(anon_sym_package); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 17: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'a') ADVANCE(20); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 18: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'a') ADVANCE(25); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 19: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'a') ADVANCE(32); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 20: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'c') ADVANCE(27); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 21: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'c') ADVANCE(12); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 22: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'e') ADVANCE(24); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 23: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'e') ADVANCE(16); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 24: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'f') ADVANCE(36); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 25: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'g') ADVANCE(23); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 26: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'i') ADVANCE(21); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 27: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'k') ADVANCE(18); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 28: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'm') ADVANCE(30); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 29: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(31); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 30: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'p') ADVANCE(29); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 31: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'r') ADVANCE(33); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 32: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(26); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 33: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(11); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 34: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(19); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 35: + ACCEPT_TOKEN(sym_identifier); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 36: + ACCEPT_TOKEN(anon_sym_def); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(35); + END_STATE(); + case 37: + ACCEPT_TOKEN(anon_sym_LF); + if (lookahead == '\n') ADVANCE(37); + END_STATE(); + case 38: + ACCEPT_TOKEN(anon_sym_SEMI); + END_STATE(); + default: + return false; + } +} + +static const TSLexMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 6}, + [2] = {.lex_state = 5}, + [3] = {.lex_state = 5}, + [4] = {.lex_state = 5}, + [5] = {.lex_state = 5}, + [6] = {.lex_state = 6}, + [7] = {.lex_state = 9}, + [8] = {.lex_state = 9}, + [9] = {.lex_state = 9}, + [10] = {.lex_state = 9}, + [11] = {.lex_state = 9}, + [12] = {.lex_state = 5}, + [13] = {.lex_state = 5}, + [14] = {.lex_state = 5}, + [15] = {.lex_state = 5}, + [16] = {.lex_state = 5}, + [17] = {.lex_state = 5}, + [18] = {.lex_state = 5}, + [19] = {.lex_state = 5}, + [20] = {.lex_state = 5}, + [21] = {.lex_state = 5}, + [22] = {.lex_state = 5}, + [23] = {.lex_state = 5}, + [24] = {.lex_state = 5}, + [25] = {.lex_state = 5}, + [26] = {.lex_state = 5}, + [27] = {.lex_state = 5}, + [28] = {.lex_state = 5}, + [29] = {.lex_state = 5}, + [30] = {.lex_state = 5}, + [31] = {.lex_state = 5}, + [32] = {.lex_state = 5}, + [33] = {.lex_state = 5}, + [34] = {.lex_state = 5}, + [35] = {.lex_state = 3}, + [36] = {.lex_state = 4}, + [37] = {.lex_state = 5}, + [38] = {.lex_state = 3}, + [39] = {.lex_state = 5}, + [40] = {.lex_state = 3}, + [41] = {.lex_state = 3}, + [42] = {.lex_state = 3}, + [43] = {.lex_state = 5}, + [44] = {.lex_state = 3}, + [45] = {.lex_state = 3}, + [46] = {.lex_state = 3}, + [47] = {.lex_state = 0}, + [48] = {.lex_state = 3}, + [49] = {.lex_state = 0}, + [50] = {.lex_state = 3}, + [51] = {.lex_state = 3}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [0] = { + [ts_builtin_sym_end] = ACTIONS(1), + [anon_sym_import] = ACTIONS(1), + [anon_sym_static] = ACTIONS(1), + [anon_sym_DOT] = ACTIONS(1), + [anon_sym_STAR] = ACTIONS(1), + [sym__shebang_comment] = ACTIONS(1), + [anon_sym_package] = ACTIONS(1), + [sym_identifier] = ACTIONS(1), + [anon_sym_def] = ACTIONS(1), + [anon_sym_SEMI] = ACTIONS(1), + }, + [1] = { + [sym_source_file] = STATE(47), + [sym_import_statement] = STATE(25), + [sym_package_definition] = STATE(4), + [sym_script_part] = STATE(20), + [sym_expression] = STATE(33), + [sym_path_expression] = STATE(30), + [sym_statement] = STATE(32), + [sym_method_declaration] = STATE(32), + [aux_sym_source_file_repeat2] = STATE(11), + [aux_sym_path_expression_repeat1] = STATE(42), + [ts_builtin_sym_end] = ACTIONS(3), + [anon_sym_import] = ACTIONS(5), + [sym__shebang_comment] = ACTIONS(7), + [anon_sym_package] = ACTIONS(9), + [sym_identifier] = ACTIONS(11), + [anon_sym_def] = ACTIONS(13), + }, + [2] = { + [sym_import_statement] = STATE(25), + [sym_script_part] = STATE(21), + [sym_expression] = STATE(33), + [sym_path_expression] = STATE(30), + [sym_statement] = STATE(32), + [sym_method_declaration] = STATE(32), + [sym__nl_semicolon] = STATE(13), + [aux_sym_source_file_repeat1] = STATE(13), + [aux_sym_source_file_repeat2] = STATE(9), + [aux_sym_path_expression_repeat1] = STATE(42), + [ts_builtin_sym_end] = ACTIONS(15), + [anon_sym_import] = ACTIONS(5), + [sym_identifier] = ACTIONS(11), + [anon_sym_def] = ACTIONS(13), + [anon_sym_LF] = ACTIONS(17), + [anon_sym_SEMI] = ACTIONS(19), + }, + [3] = { + [sym_import_statement] = STATE(25), + [sym_script_part] = STATE(22), + [sym_expression] = STATE(33), + [sym_path_expression] = STATE(30), + [sym_statement] = STATE(32), + [sym_method_declaration] = STATE(32), + [sym__nl_semicolon] = STATE(13), + [aux_sym_source_file_repeat1] = STATE(13), + [aux_sym_source_file_repeat2] = STATE(8), + [aux_sym_path_expression_repeat1] = STATE(42), + [ts_builtin_sym_end] = ACTIONS(21), + [anon_sym_import] = ACTIONS(5), + [sym_identifier] = ACTIONS(11), + [anon_sym_def] = ACTIONS(13), + [anon_sym_LF] = ACTIONS(17), + [anon_sym_SEMI] = ACTIONS(19), + }, + [4] = { + [sym_import_statement] = STATE(25), + [sym_script_part] = STATE(19), + [sym_expression] = STATE(33), + [sym_path_expression] = STATE(30), + [sym_statement] = STATE(32), + [sym_method_declaration] = STATE(32), + [sym__nl_semicolon] = STATE(2), + [aux_sym_source_file_repeat1] = STATE(2), + [aux_sym_source_file_repeat2] = STATE(10), + [aux_sym_path_expression_repeat1] = STATE(42), + [ts_builtin_sym_end] = ACTIONS(23), + [anon_sym_import] = ACTIONS(5), + [sym_identifier] = ACTIONS(11), + [anon_sym_def] = ACTIONS(13), + [anon_sym_LF] = ACTIONS(25), + [anon_sym_SEMI] = ACTIONS(27), + }, + [5] = { + [sym_import_statement] = STATE(25), + [sym_script_part] = STATE(21), + [sym_expression] = STATE(33), + [sym_path_expression] = STATE(30), + [sym_statement] = STATE(32), + [sym_method_declaration] = STATE(32), + [sym__nl_semicolon] = STATE(3), + [aux_sym_source_file_repeat1] = STATE(3), + [aux_sym_source_file_repeat2] = STATE(9), + [aux_sym_path_expression_repeat1] = STATE(42), + [ts_builtin_sym_end] = ACTIONS(15), + [anon_sym_import] = ACTIONS(5), + [sym_identifier] = ACTIONS(11), + [anon_sym_def] = ACTIONS(13), + [anon_sym_LF] = ACTIONS(29), + [anon_sym_SEMI] = ACTIONS(31), + }, + [6] = { + [sym_import_statement] = STATE(25), + [sym_package_definition] = STATE(5), + [sym_script_part] = STATE(19), + [sym_expression] = STATE(33), + [sym_path_expression] = STATE(30), + [sym_statement] = STATE(32), + [sym_method_declaration] = STATE(32), + [aux_sym_source_file_repeat2] = STATE(10), + [aux_sym_path_expression_repeat1] = STATE(42), + [ts_builtin_sym_end] = ACTIONS(23), + [anon_sym_import] = ACTIONS(5), + [anon_sym_package] = ACTIONS(9), + [sym_identifier] = ACTIONS(11), + [anon_sym_def] = ACTIONS(13), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 10, + ACTIONS(33), 1, + ts_builtin_sym_end, + ACTIONS(35), 1, + anon_sym_import, + ACTIONS(38), 1, + sym_identifier, + ACTIONS(41), 1, + anon_sym_def, + STATE(7), 1, + aux_sym_source_file_repeat2, + STATE(30), 1, + sym_path_expression, + STATE(33), 1, + sym_expression, + STATE(42), 1, + aux_sym_path_expression_repeat1, + STATE(25), 2, + sym_import_statement, + sym_script_part, + STATE(32), 2, + sym_statement, + sym_method_declaration, + [33] = 11, + ACTIONS(5), 1, + anon_sym_import, + ACTIONS(11), 1, + sym_identifier, + ACTIONS(13), 1, + anon_sym_def, + ACTIONS(44), 1, + ts_builtin_sym_end, + STATE(7), 1, + aux_sym_source_file_repeat2, + STATE(18), 1, + sym_script_part, + STATE(25), 1, + sym_import_statement, + STATE(30), 1, + sym_path_expression, + STATE(33), 1, + sym_expression, + STATE(42), 1, + aux_sym_path_expression_repeat1, + STATE(32), 2, + sym_statement, + sym_method_declaration, + [68] = 11, + ACTIONS(5), 1, + anon_sym_import, + ACTIONS(11), 1, + sym_identifier, + ACTIONS(13), 1, + anon_sym_def, + ACTIONS(21), 1, + ts_builtin_sym_end, + STATE(7), 1, + aux_sym_source_file_repeat2, + STATE(22), 1, + sym_script_part, + STATE(25), 1, + sym_import_statement, + STATE(30), 1, + sym_path_expression, + STATE(33), 1, + sym_expression, + STATE(42), 1, + aux_sym_path_expression_repeat1, + STATE(32), 2, + sym_statement, + sym_method_declaration, + [103] = 11, + ACTIONS(5), 1, + anon_sym_import, + ACTIONS(11), 1, + sym_identifier, + ACTIONS(13), 1, + anon_sym_def, + ACTIONS(15), 1, + ts_builtin_sym_end, + STATE(7), 1, + aux_sym_source_file_repeat2, + STATE(21), 1, + sym_script_part, + STATE(25), 1, + sym_import_statement, + STATE(30), 1, + sym_path_expression, + STATE(33), 1, + sym_expression, + STATE(42), 1, + aux_sym_path_expression_repeat1, + STATE(32), 2, + sym_statement, + sym_method_declaration, + [138] = 11, + ACTIONS(5), 1, + anon_sym_import, + ACTIONS(11), 1, + sym_identifier, + ACTIONS(13), 1, + anon_sym_def, + ACTIONS(23), 1, + ts_builtin_sym_end, + STATE(7), 1, + aux_sym_source_file_repeat2, + STATE(19), 1, + sym_script_part, + STATE(25), 1, + sym_import_statement, + STATE(30), 1, + sym_path_expression, + STATE(33), 1, + sym_expression, + STATE(42), 1, + aux_sym_path_expression_repeat1, + STATE(32), 2, + sym_statement, + sym_method_declaration, + [173] = 4, + ACTIONS(50), 1, + anon_sym_DOT, + STATE(12), 1, + aux_sym_import_statement_repeat1, + ACTIONS(46), 2, + ts_builtin_sym_end, + anon_sym_LF, + ACTIONS(48), 4, + anon_sym_import, + sym_identifier, + anon_sym_def, + anon_sym_SEMI, + [190] = 5, + ACTIONS(53), 1, + ts_builtin_sym_end, + ACTIONS(57), 1, + anon_sym_LF, + ACTIONS(60), 1, + anon_sym_SEMI, + STATE(13), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + ACTIONS(55), 3, + anon_sym_import, + sym_identifier, + anon_sym_def, + [209] = 4, + ACTIONS(67), 1, + anon_sym_DOT, + STATE(12), 1, + aux_sym_import_statement_repeat1, + ACTIONS(63), 2, + ts_builtin_sym_end, + anon_sym_LF, + ACTIONS(65), 4, + anon_sym_import, + sym_identifier, + anon_sym_def, + anon_sym_SEMI, + [226] = 4, + ACTIONS(67), 1, + anon_sym_DOT, + STATE(14), 1, + aux_sym_import_statement_repeat1, + ACTIONS(69), 2, + ts_builtin_sym_end, + anon_sym_LF, + ACTIONS(71), 4, + anon_sym_import, + sym_identifier, + anon_sym_def, + anon_sym_SEMI, + [243] = 5, + ACTIONS(17), 1, + anon_sym_LF, + ACTIONS(19), 1, + anon_sym_SEMI, + ACTIONS(33), 1, + ts_builtin_sym_end, + STATE(13), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + ACTIONS(73), 3, + anon_sym_import, + sym_identifier, + anon_sym_def, + [262] = 2, + ACTIONS(46), 2, + ts_builtin_sym_end, + anon_sym_LF, + ACTIONS(48), 5, + anon_sym_import, + anon_sym_DOT, + sym_identifier, + anon_sym_def, + anon_sym_SEMI, + [274] = 4, + ACTIONS(75), 1, + ts_builtin_sym_end, + ACTIONS(77), 1, + anon_sym_LF, + ACTIONS(79), 1, + anon_sym_SEMI, + STATE(16), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + [288] = 4, + ACTIONS(15), 1, + ts_builtin_sym_end, + ACTIONS(77), 1, + anon_sym_LF, + ACTIONS(79), 1, + anon_sym_SEMI, + STATE(16), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + [302] = 4, + ACTIONS(23), 1, + ts_builtin_sym_end, + ACTIONS(77), 1, + anon_sym_LF, + ACTIONS(79), 1, + anon_sym_SEMI, + STATE(16), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + [316] = 4, + ACTIONS(21), 1, + ts_builtin_sym_end, + ACTIONS(77), 1, + anon_sym_LF, + ACTIONS(79), 1, + anon_sym_SEMI, + STATE(16), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + [330] = 4, + ACTIONS(44), 1, + ts_builtin_sym_end, + ACTIONS(77), 1, + anon_sym_LF, + ACTIONS(79), 1, + anon_sym_SEMI, + STATE(16), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + [344] = 4, + ACTIONS(81), 1, + anon_sym_DOT, + ACTIONS(83), 1, + anon_sym_LF, + ACTIONS(85), 1, + anon_sym_SEMI, + STATE(12), 1, + aux_sym_import_statement_repeat1, + [357] = 4, + ACTIONS(87), 1, + anon_sym_DOT, + ACTIONS(89), 1, + anon_sym_LF, + ACTIONS(91), 1, + anon_sym_SEMI, + STATE(29), 1, + aux_sym_import_statement_repeat1, + [370] = 3, + ACTIONS(77), 1, + anon_sym_LF, + ACTIONS(79), 1, + anon_sym_SEMI, + STATE(16), 2, + sym__nl_semicolon, + aux_sym_source_file_repeat1, + [381] = 3, + ACTIONS(95), 1, + anon_sym_DOT, + ACTIONS(97), 1, + anon_sym_SEMI, + ACTIONS(93), 2, + ts_builtin_sym_end, + anon_sym_LF, + [392] = 3, + ACTIONS(95), 1, + anon_sym_DOT, + ACTIONS(101), 1, + anon_sym_SEMI, + ACTIONS(99), 2, + ts_builtin_sym_end, + anon_sym_LF, + [403] = 4, + ACTIONS(103), 1, + anon_sym_DOT, + ACTIONS(105), 1, + anon_sym_LF, + ACTIONS(107), 1, + anon_sym_SEMI, + STATE(23), 1, + aux_sym_import_statement_repeat1, + [416] = 4, + ACTIONS(109), 1, + anon_sym_DOT, + ACTIONS(111), 1, + anon_sym_LF, + ACTIONS(113), 1, + anon_sym_SEMI, + STATE(12), 1, + aux_sym_import_statement_repeat1, + [429] = 2, + ACTIONS(117), 1, + anon_sym_SEMI, + ACTIONS(115), 2, + ts_builtin_sym_end, + anon_sym_LF, + [437] = 2, + ACTIONS(121), 1, + anon_sym_SEMI, + ACTIONS(119), 2, + ts_builtin_sym_end, + anon_sym_LF, + [445] = 2, + ACTIONS(125), 1, + anon_sym_SEMI, + ACTIONS(123), 2, + ts_builtin_sym_end, + anon_sym_LF, + [453] = 2, + ACTIONS(129), 1, + anon_sym_SEMI, + ACTIONS(127), 2, + ts_builtin_sym_end, + anon_sym_LF, + [461] = 2, + ACTIONS(131), 1, + anon_sym_LF, + ACTIONS(133), 1, + anon_sym_SEMI, + [468] = 2, + ACTIONS(135), 1, + anon_sym_STAR, + ACTIONS(137), 1, + sym_identifier, + [475] = 2, + ACTIONS(139), 1, + anon_sym_static, + ACTIONS(141), 1, + sym_identifier, + [482] = 2, + ACTIONS(143), 1, + anon_sym_LF, + ACTIONS(145), 1, + anon_sym_SEMI, + [489] = 2, + ACTIONS(147), 1, + sym_identifier, + STATE(38), 1, + aux_sym_path_expression_repeat1, + [496] = 2, + ACTIONS(150), 1, + anon_sym_LF, + ACTIONS(152), 1, + anon_sym_SEMI, + [503] = 2, + ACTIONS(137), 1, + sym_identifier, + ACTIONS(154), 1, + anon_sym_STAR, + [510] = 2, + ACTIONS(137), 1, + sym_identifier, + ACTIONS(156), 1, + anon_sym_STAR, + [517] = 2, + ACTIONS(158), 1, + sym_identifier, + STATE(38), 1, + aux_sym_path_expression_repeat1, + [524] = 2, + ACTIONS(160), 1, + anon_sym_LF, + ACTIONS(162), 1, + anon_sym_SEMI, + [531] = 2, + ACTIONS(137), 1, + sym_identifier, + ACTIONS(164), 1, + anon_sym_STAR, + [538] = 1, + ACTIONS(166), 1, + sym_identifier, + [542] = 1, + ACTIONS(168), 1, + sym_identifier, + [546] = 1, + ACTIONS(170), 1, + ts_builtin_sym_end, + [550] = 1, + ACTIONS(137), 1, + sym_identifier, + [554] = 1, + ACTIONS(172), 1, + anon_sym_DOT, + [558] = 1, + ACTIONS(174), 1, + sym_identifier, + [562] = 1, + ACTIONS(176), 1, + sym_identifier, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(7)] = 0, + [SMALL_STATE(8)] = 33, + [SMALL_STATE(9)] = 68, + [SMALL_STATE(10)] = 103, + [SMALL_STATE(11)] = 138, + [SMALL_STATE(12)] = 173, + [SMALL_STATE(13)] = 190, + [SMALL_STATE(14)] = 209, + [SMALL_STATE(15)] = 226, + [SMALL_STATE(16)] = 243, + [SMALL_STATE(17)] = 262, + [SMALL_STATE(18)] = 274, + [SMALL_STATE(19)] = 288, + [SMALL_STATE(20)] = 302, + [SMALL_STATE(21)] = 316, + [SMALL_STATE(22)] = 330, + [SMALL_STATE(23)] = 344, + [SMALL_STATE(24)] = 357, + [SMALL_STATE(25)] = 370, + [SMALL_STATE(26)] = 381, + [SMALL_STATE(27)] = 392, + [SMALL_STATE(28)] = 403, + [SMALL_STATE(29)] = 416, + [SMALL_STATE(30)] = 429, + [SMALL_STATE(31)] = 437, + [SMALL_STATE(32)] = 445, + [SMALL_STATE(33)] = 453, + [SMALL_STATE(34)] = 461, + [SMALL_STATE(35)] = 468, + [SMALL_STATE(36)] = 475, + [SMALL_STATE(37)] = 482, + [SMALL_STATE(38)] = 489, + [SMALL_STATE(39)] = 496, + [SMALL_STATE(40)] = 503, + [SMALL_STATE(41)] = 510, + [SMALL_STATE(42)] = 517, + [SMALL_STATE(43)] = 524, + [SMALL_STATE(44)] = 531, + [SMALL_STATE(45)] = 538, + [SMALL_STATE(46)] = 542, + [SMALL_STATE(47)] = 546, + [SMALL_STATE(48)] = 550, + [SMALL_STATE(49)] = 554, + [SMALL_STATE(50)] = 558, + [SMALL_STATE(51)] = 562, +}; + +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), + [5] = {.entry = {.count = 1, .reusable = false}}, SHIFT(36), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6), + [9] = {.entry = {.count = 1, .reusable = false}}, SHIFT(50), + [11] = {.entry = {.count = 1, .reusable = false}}, SHIFT(26), + [13] = {.entry = {.count = 1, .reusable = false}}, SHIFT(46), + [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 2), + [17] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [19] = {.entry = {.count = 1, .reusable = false}}, SHIFT(13), + [21] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 3), + [23] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1), + [25] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), + [27] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2), + [29] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), + [31] = {.entry = {.count = 1, .reusable = false}}, SHIFT(3), + [33] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat2, 2), + [35] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat2, 2), SHIFT_REPEAT(36), + [38] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat2, 2), SHIFT_REPEAT(26), + [41] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat2, 2), SHIFT_REPEAT(46), + [44] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 4), + [46] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_import_statement_repeat1, 2), + [48] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_import_statement_repeat1, 2), + [50] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_import_statement_repeat1, 2), SHIFT_REPEAT(48), + [53] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), + [55] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2), + [57] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(13), + [60] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(13), + [63] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_package_definition, 3, .production_id = 3), + [65] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_package_definition, 3, .production_id = 3), + [67] = {.entry = {.count = 1, .reusable = false}}, SHIFT(48), + [69] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_package_definition, 2, .production_id = 1), + [71] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_package_definition, 2, .production_id = 1), + [73] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_source_file_repeat2, 2), + [75] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 5), + [77] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), + [79] = {.entry = {.count = 1, .reusable = false}}, SHIFT(16), + [81] = {.entry = {.count = 1, .reusable = false}}, SHIFT(40), + [83] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 4, .production_id = 4), + [85] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 4, .production_id = 4), + [87] = {.entry = {.count = 1, .reusable = false}}, SHIFT(35), + [89] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 2, .production_id = 1), + [91] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 2, .production_id = 1), + [93] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_path_expression, 1), + [95] = {.entry = {.count = 1, .reusable = false}}, SHIFT(45), + [97] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_path_expression, 1), + [99] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_path_expression, 2), + [101] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_path_expression, 2), + [103] = {.entry = {.count = 1, .reusable = false}}, SHIFT(41), + [105] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 3, .production_id = 2), + [107] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 3, .production_id = 2), + [109] = {.entry = {.count = 1, .reusable = false}}, SHIFT(44), + [111] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 3, .production_id = 3), + [113] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 3, .production_id = 3), + [115] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_expression, 1), + [117] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_expression, 1), + [119] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_method_declaration, 2, .production_id = 1), + [121] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_method_declaration, 2, .production_id = 1), + [123] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_script_part, 1), + [125] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_script_part, 1), + [127] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_statement, 1), + [129] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_statement, 1), + [131] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 5, .production_id = 6), + [133] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 5, .production_id = 6), + [135] = {.entry = {.count = 1, .reusable = true}}, SHIFT(43), + [137] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), + [139] = {.entry = {.count = 1, .reusable = false}}, SHIFT(51), + [141] = {.entry = {.count = 1, .reusable = false}}, SHIFT(24), + [143] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 6, .production_id = 8), + [145] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 6, .production_id = 8), + [147] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_path_expression_repeat1, 2), SHIFT_REPEAT(49), + [150] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 5, .production_id = 7), + [152] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 5, .production_id = 7), + [154] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), + [156] = {.entry = {.count = 1, .reusable = true}}, SHIFT(34), + [158] = {.entry = {.count = 1, .reusable = true}}, SHIFT(27), + [160] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_statement, 4, .production_id = 5), + [162] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_import_statement, 4, .production_id = 5), + [164] = {.entry = {.count = 1, .reusable = true}}, SHIFT(39), + [166] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_path_expression_repeat1, 2), + [168] = {.entry = {.count = 1, .reusable = true}}, SHIFT(31), + [170] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [172] = {.entry = {.count = 1, .reusable = true}}, SHIFT(45), + [174] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), + [176] = {.entry = {.count = 1, .reusable = true}}, SHIFT(28), +}; + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef _WIN32 +#define extern __declspec(dllexport) +#endif + +extern const TSLanguage *tree_sitter_Groovy(void) { + static const TSLanguage language = { + .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, + .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 = ts_lex_modes, + .lex_fn = ts_lex, + .primary_state_ids = ts_primary_state_ids, + }; + return &language; +} +#ifdef __cplusplus +} +#endif diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h new file mode 100644 index 0000000..2b14ac1 --- /dev/null +++ b/src/tree_sitter/parser.h @@ -0,0 +1,224 @@ +#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 + +typedef uint16_t TSStateId; + +#ifndef TREE_SITTER_API_H_ +typedef uint16_t TSSymbol; +typedef uint16_t TSFieldId; +typedef struct TSLanguage TSLanguage; +#endif + +typedef struct { + TSFieldId field_id; + uint8_t child_index; + bool inherited; +} TSFieldMapEntry; + +typedef struct { + uint16_t index; + uint16_t length; +} TSFieldMapSlice; + +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 *); +}; + +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 union { + TSParseAction action; + struct { + uint8_t count; + bool reusable; + } entry; +} TSParseActionEntry; + +struct TSLanguage { + uint32_t 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 TSFieldMapSlice *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 TSLexMode *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; +}; + +/* + * Lexer Macros + */ + +#define START_LEXER() \ + bool result = false; \ + bool skip = false; \ + 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 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_val, child_count_val, ...) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_val, \ + .child_count = child_count_val, \ + __VA_ARGS__ \ + }, \ + }} + +#define RECOVER() \ + {{ \ + .type = TSParseActionTypeRecover \ + }} + +#define ACCEPT_INPUT() \ + {{ \ + .type = TSParseActionTypeAccept \ + }} + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_ diff --git a/test/corpus/import statements.txt b/test/corpus/import statements.txt new file mode 100644 index 0000000..ad11fd3 --- /dev/null +++ b/test/corpus/import statements.txt @@ -0,0 +1,47 @@ +================================================================================ +single identifier import +================================================================================ +import wibble + +-------------------------------------------------------------------------------- + +(source_file + (import_statement + (identifier))) + +================================================================================ +multiple identifier import +================================================================================ +import wobble.qq + +-------------------------------------------------------------------------------- + +(source_file + (import_statement + (identifier) + (identifier))) + +================================================================================ +wildcard import +================================================================================ +import flobble.fnurfle.* + +-------------------------------------------------------------------------------- + +(source_file + (import_statement + (identifier) + (identifier))) + +================================================================================ +multiple imports semicolon separated +================================================================================ +import qq.ss; import flobble.*; +-------------------------------------------------------------------------------- + +(source_file + (import_statement + (identifier) + (identifier)) + (import_statement + (identifier))) diff --git a/test/corpus/package definition.txt b/test/corpus/package definition.txt new file mode 100644 index 0000000..69502c1 --- /dev/null +++ b/test/corpus/package definition.txt @@ -0,0 +1,20 @@ +================================================================================ +Simple package definition +================================================================================ +package flob +-------------------------------------------------------------------------------- + +(source_file + (package_definition + (identifier))) + +================================================================================ +Dotted package definition +================================================================================ +package flob.wibble +-------------------------------------------------------------------------------- + +(source_file + (package_definition + (identifier) + (identifier))) diff --git a/test/corpus/shebang.txt b/test/corpus/shebang.txt new file mode 100644 index 0000000..5615067 --- /dev/null +++ b/test/corpus/shebang.txt @@ -0,0 +1,33 @@ +================================================================================ +Shebang ignored at beginning of first line +================================================================================ +#!/usr/bin/env groovy +hello +-------------------------------------------------------------------------------- + +(source_file + (script_part + (statement + (expression + (path_expression + (identifier)))))) + +================================================================================ +Shebang not ignored after first character +================================================================================ + #!/usr/bin/env groovy +-------------------------------------------------------------------------------- + +(source_file + (ERROR + (UNEXPECTED '#') + (identifier) + (UNEXPECTED '/') + (identifier) + (UNEXPECTED '/') + (identifier)) + (script_part + (statement + (expression + (path_expression + (identifier)))))) diff --git a/test/corpus/statements.txt b/test/corpus/statements.txt new file mode 100644 index 0000000..1443cc2 --- /dev/null +++ b/test/corpus/statements.txt @@ -0,0 +1,90 @@ +================================================================================ +Empty File +================================================================================ + +-------------------------------------------------------------------------------- + +(source_file) + +================================================================================ +statement - single identifier +================================================================================ +hello +-------------------------------------------------------------------------------- + +(source_file + (script_part + (statement + (expression + (path_expression + (identifier)))))) + +================================================================================ +statement - Simple method definition +================================================================================ +def hello +-------------------------------------------------------------------------------- + +(source_file + (script_part + (method_declaration + (identifier)))) + +================================================================================ +statement - Multiple statements same line +================================================================================ +hello;goodbye;def flunk +-------------------------------------------------------------------------------- + +(source_file + (script_part + (statement + (expression + (path_expression + (identifier))))) + (script_part + (statement + (expression + (path_expression + (identifier))))) + (script_part + (method_declaration + (identifier)))) + +================================================================================ +statement - Multiple Statements, Multiple Lines +================================================================================ +hello +def flunk +goodbye; +-------------------------------------------------------------------------------- + +(source_file + (script_part + (statement + (expression + (path_expression + (identifier))))) + (script_part + (method_declaration + (identifier))) + (script_part + (statement + (expression + (path_expression + (identifier)))))) + +================================================================================ +statement - path expression multiple parts +================================================================================ +wibble.wobble.q +-------------------------------------------------------------------------------- + +(source_file + (script_part + (statement + (expression + (path_expression + (identifier) + (identifier) + (identifier))))))