From 284103c1a8103c344c9dd15166d2e81c38e39cc1 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sun, 21 May 2023 20:01:36 +0300 Subject: [PATCH] initial commit --- .gitignore | 2 + Cargo.lock | 59 ++ Cargo.toml | 26 + LICENSE | 20 + binding.gyp | 19 + bindings/node/binding.cc | 28 + bindings/node/index.js | 19 + bindings/rust/build.rs | 40 ++ bindings/rust/lib.rs | 52 ++ example-file | 12 + grammar.js | 49 ++ package-lock.json | 47 ++ package.json | 21 + queries/highlights.scm | 7 + src/grammar.json | 240 ++++++++ src/node-types.json | 170 ++++++ src/parser.c | 1196 ++++++++++++++++++++++++++++++++++++++ src/tree_sitter/parser.h | 224 +++++++ 18 files changed, 2231 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE 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 example-file create mode 100644 grammar.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 queries/highlights.scm 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c085d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c0c87e9 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,59 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" +dependencies = [ + "memchr", +] + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "regex" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" + +[[package]] +name = "tree-sitter" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e747b1f9b7b931ed39a548c1fae149101497de3c1fc8d9e18c62c1a66c683d3d" +dependencies = [ + "cc", + "regex", +] + +[[package]] +name = "tree-sitter-uci" +version = "0.0.1" +dependencies = [ + "cc", + "tree-sitter", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d04edbc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "tree-sitter-uci" +description = "uci grammar for the tree-sitter parsing library" +version = "0.0.1" +keywords = ["incremental", "parsing", "uci"] +categories = ["parsing", "text-editors"] +repository = "https://github.com/tree-sitter/tree-sitter-uci" +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.10" + +[build-dependencies] +cc = "1.0" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..721841b --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) +Copyright © 2023 Rokas Puzonas + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..cb5e247 --- /dev/null +++ b/binding.gyp @@ -0,0 +1,19 @@ +{ + "targets": [ + { + "target_name": "tree_sitter_uci_binding", + "include_dirs": [ + " +#include "nan.h" + +using namespace v8; + +extern "C" TSLanguage * tree_sitter_uci(); + +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_uci()); + + Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("uci").ToLocalChecked()); + Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); +} + +NODE_MODULE(tree_sitter_uci_binding, Init) + +} // namespace diff --git a/bindings/node/index.js b/bindings/node/index.js new file mode 100644 index 0000000..26497d4 --- /dev/null +++ b/bindings/node/index.js @@ -0,0 +1,19 @@ +try { + module.exports = require("../../build/Release/tree_sitter_uci_binding"); +} catch (error1) { + if (error1.code !== 'MODULE_NOT_FOUND') { + throw error1; + } + try { + module.exports = require("../../build/Debug/tree_sitter_uci_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..0790fc6 --- /dev/null +++ b/bindings/rust/lib.rs @@ -0,0 +1,52 @@ +//! This crate provides uci 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_uci::language()).expect("Error loading uci 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_uci() -> 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_uci() } +} + +/// 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 uci language"); + } +} diff --git a/example-file b/example-file new file mode 100644 index 0000000..4425718 --- /dev/null +++ b/example-file @@ -0,0 +1,12 @@ +package 'example' + +config 'example' 'test' + option 'string' 'some value' + option 'boolean' '1' + list 'collection' 'first item' + list 'collection' 'second item' + option example value + option example "value" + option 'example' value + option 'example' "value" + option "example" 'value' diff --git a/grammar.js b/grammar.js new file mode 100644 index 0000000..4457076 --- /dev/null +++ b/grammar.js @@ -0,0 +1,49 @@ +module.exports = grammar( +{ + name: 'uci', + + extras: $ => [ + $.comment, + /[\s\p{Zs}\uFEFF\u2060\u200B]/, + ], + + rules: { + config_file: $ => repeat(choice( + $.package, + $.config + )), + _name_fragment: $ => /[A-Za-z0-9]+/, + name: $ => choice( + $._name_fragment, + seq('"', $._name_fragment, '"'), + seq("'", $._name_fragment, "'"), + ), + string: $ => choice( + /"[^"\\]*"/, + /'[^'\\]*'/, + /[^'"\s]+/ + ), + config: $ => seq( + "config", + field("type", $.name), + optional(field("name", $.name)), + repeat(choice($.option, $.list)) + ), + package: $ => prec.right(seq( + "package", + $.name, + repeat($.config) + )), + option: $ => seq( + "option", + field("key", $.name), + field("value", $.string), + ), + list: $ => seq( + "list", + field("key", $.name), + field("value", $.string), + ), + comment: $ => token(seq("#", /.*/)) + } +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c4a3162 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,47 @@ +{ + "name": "tree-sitter-uci", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "tree-sitter-uci", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "nan": "^2.17.0" + }, + "devDependencies": { + "tree-sitter-cli": "^0.20.8" + } + }, + "node_modules/nan": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz", + "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==" + }, + "node_modules/tree-sitter-cli": { + "version": "0.20.8", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.8.tgz", + "integrity": "sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "tree-sitter": "cli.js" + } + } + }, + "dependencies": { + "nan": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz", + "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==" + }, + "tree-sitter-cli": { + "version": "0.20.8", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.8.tgz", + "integrity": "sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..745cbd5 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "tree-sitter-uci", + "version": "1.0.0", + "description": "", + "author": "Rokas Puzonas", + "license": "MIT", + "dependencies": { + "nan": "^2.17.0" + }, + "devDependencies": { + "tree-sitter-cli": "^0.20.8" + }, + "main": "bindings/node", + "tree-sitter": [ + { + "scope": "source.uci", + "file-types": [ "uci" ], + "content-regex": "config|package" + } + ] +} diff --git a/queries/highlights.scm b/queries/highlights.scm new file mode 100644 index 0000000..7a7b323 --- /dev/null +++ b/queries/highlights.scm @@ -0,0 +1,7 @@ +"package" @keyword +"config" @keyword +"option" @keyword +"list" @keyword + +(name) @string +(string) @string diff --git a/src/grammar.json b/src/grammar.json new file mode 100644 index 0000000..aa84e27 --- /dev/null +++ b/src/grammar.json @@ -0,0 +1,240 @@ +{ + "name": "uci", + "rules": { + "config_file": { + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "package" + }, + { + "type": "SYMBOL", + "name": "config" + } + ] + } + }, + "_name_fragment": { + "type": "PATTERN", + "value": "[A-Za-z0-9]+" + }, + "name": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_name_fragment" + }, + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "\"" + }, + { + "type": "SYMBOL", + "name": "_name_fragment" + }, + { + "type": "STRING", + "value": "\"" + } + ] + }, + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "'" + }, + { + "type": "SYMBOL", + "name": "_name_fragment" + }, + { + "type": "STRING", + "value": "'" + } + ] + } + ] + }, + "string": { + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "\"[^\"\\\\]*\"" + }, + { + "type": "PATTERN", + "value": "'[^'\\\\]*'" + }, + { + "type": "PATTERN", + "value": "[^'\"\\s]+" + } + ] + }, + "config": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "config" + }, + { + "type": "FIELD", + "name": "type", + "content": { + "type": "SYMBOL", + "name": "name" + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "FIELD", + "name": "name", + "content": { + "type": "SYMBOL", + "name": "name" + } + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "option" + }, + { + "type": "SYMBOL", + "name": "list" + } + ] + } + } + ] + }, + "package": { + "type": "PREC_RIGHT", + "value": 0, + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "package" + }, + { + "type": "SYMBOL", + "name": "name" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "config" + } + } + ] + } + }, + "option": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "option" + }, + { + "type": "FIELD", + "name": "key", + "content": { + "type": "SYMBOL", + "name": "name" + } + }, + { + "type": "FIELD", + "name": "value", + "content": { + "type": "SYMBOL", + "name": "string" + } + } + ] + }, + "list": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "list" + }, + { + "type": "FIELD", + "name": "key", + "content": { + "type": "SYMBOL", + "name": "name" + } + }, + { + "type": "FIELD", + "name": "value", + "content": { + "type": "SYMBOL", + "name": "string" + } + } + ] + }, + "comment": { + "type": "TOKEN", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "#" + }, + { + "type": "PATTERN", + "value": ".*" + } + ] + } + } + }, + "extras": [ + { + "type": "SYMBOL", + "name": "comment" + }, + { + "type": "PATTERN", + "value": "[\\s\\p{Zs}\\uFEFF\\u2060\\u200B]" + } + ], + "conflicts": [], + "precedences": [], + "externals": [], + "inline": [], + "supertypes": [] +} + diff --git a/src/node-types.json b/src/node-types.json new file mode 100644 index 0000000..e355ff7 --- /dev/null +++ b/src/node-types.json @@ -0,0 +1,170 @@ +[ + { + "type": "config", + "named": true, + "fields": { + "name": { + "multiple": false, + "required": false, + "types": [ + { + "type": "name", + "named": true + } + ] + }, + "type": { + "multiple": false, + "required": true, + "types": [ + { + "type": "name", + "named": true + } + ] + } + }, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "list", + "named": true + }, + { + "type": "option", + "named": true + } + ] + } + }, + { + "type": "config_file", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "config", + "named": true + }, + { + "type": "package", + "named": true + } + ] + } + }, + { + "type": "list", + "named": true, + "fields": { + "key": { + "multiple": false, + "required": true, + "types": [ + { + "type": "name", + "named": true + } + ] + }, + "value": { + "multiple": false, + "required": true, + "types": [ + { + "type": "string", + "named": true + } + ] + } + } + }, + { + "type": "name", + "named": true, + "fields": {} + }, + { + "type": "option", + "named": true, + "fields": { + "key": { + "multiple": false, + "required": true, + "types": [ + { + "type": "name", + "named": true + } + ] + }, + "value": { + "multiple": false, + "required": true, + "types": [ + { + "type": "string", + "named": true + } + ] + } + } + }, + { + "type": "package", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "config", + "named": true + }, + { + "type": "name", + "named": true + } + ] + } + }, + { + "type": "string", + "named": true, + "fields": {} + }, + { + "type": "\"", + "named": false + }, + { + "type": "'", + "named": false + }, + { + "type": "comment", + "named": true + }, + { + "type": "config", + "named": false + }, + { + "type": "list", + "named": false + }, + { + "type": "option", + "named": false + }, + { + "type": "package", + "named": false + } +] \ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..3c8eb64 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,1196 @@ +#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 40 +#define LARGE_STATE_COUNT 3 +#define SYMBOL_COUNT 22 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 12 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 4 +#define MAX_ALIAS_SEQUENCE_LENGTH 4 +#define PRODUCTION_ID_COUNT 4 + +enum { + sym__name_fragment = 1, + anon_sym_DQUOTE = 2, + anon_sym_SQUOTE = 3, + aux_sym_string_token1 = 4, + aux_sym_string_token2 = 5, + aux_sym_string_token3 = 6, + anon_sym_config = 7, + anon_sym_package = 8, + anon_sym_option = 9, + anon_sym_list = 10, + sym_comment = 11, + sym_config_file = 12, + sym_name = 13, + sym_string = 14, + sym_config = 15, + sym_package = 16, + sym_option = 17, + sym_list = 18, + aux_sym_config_file_repeat1 = 19, + aux_sym_config_repeat1 = 20, + aux_sym_package_repeat1 = 21, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [sym__name_fragment] = "_name_fragment", + [anon_sym_DQUOTE] = "\"", + [anon_sym_SQUOTE] = "'", + [aux_sym_string_token1] = "string_token1", + [aux_sym_string_token2] = "string_token2", + [aux_sym_string_token3] = "string_token3", + [anon_sym_config] = "config", + [anon_sym_package] = "package", + [anon_sym_option] = "option", + [anon_sym_list] = "list", + [sym_comment] = "comment", + [sym_config_file] = "config_file", + [sym_name] = "name", + [sym_string] = "string", + [sym_config] = "config", + [sym_package] = "package", + [sym_option] = "option", + [sym_list] = "list", + [aux_sym_config_file_repeat1] = "config_file_repeat1", + [aux_sym_config_repeat1] = "config_repeat1", + [aux_sym_package_repeat1] = "package_repeat1", +}; + +static const TSSymbol ts_symbol_map[] = { + [ts_builtin_sym_end] = ts_builtin_sym_end, + [sym__name_fragment] = sym__name_fragment, + [anon_sym_DQUOTE] = anon_sym_DQUOTE, + [anon_sym_SQUOTE] = anon_sym_SQUOTE, + [aux_sym_string_token1] = aux_sym_string_token1, + [aux_sym_string_token2] = aux_sym_string_token2, + [aux_sym_string_token3] = aux_sym_string_token3, + [anon_sym_config] = anon_sym_config, + [anon_sym_package] = anon_sym_package, + [anon_sym_option] = anon_sym_option, + [anon_sym_list] = anon_sym_list, + [sym_comment] = sym_comment, + [sym_config_file] = sym_config_file, + [sym_name] = sym_name, + [sym_string] = sym_string, + [sym_config] = sym_config, + [sym_package] = sym_package, + [sym_option] = sym_option, + [sym_list] = sym_list, + [aux_sym_config_file_repeat1] = aux_sym_config_file_repeat1, + [aux_sym_config_repeat1] = aux_sym_config_repeat1, + [aux_sym_package_repeat1] = aux_sym_package_repeat1, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [sym__name_fragment] = { + .visible = false, + .named = true, + }, + [anon_sym_DQUOTE] = { + .visible = true, + .named = false, + }, + [anon_sym_SQUOTE] = { + .visible = true, + .named = false, + }, + [aux_sym_string_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_string_token2] = { + .visible = false, + .named = false, + }, + [aux_sym_string_token3] = { + .visible = false, + .named = false, + }, + [anon_sym_config] = { + .visible = true, + .named = false, + }, + [anon_sym_package] = { + .visible = true, + .named = false, + }, + [anon_sym_option] = { + .visible = true, + .named = false, + }, + [anon_sym_list] = { + .visible = true, + .named = false, + }, + [sym_comment] = { + .visible = true, + .named = true, + }, + [sym_config_file] = { + .visible = true, + .named = true, + }, + [sym_name] = { + .visible = true, + .named = true, + }, + [sym_string] = { + .visible = true, + .named = true, + }, + [sym_config] = { + .visible = true, + .named = true, + }, + [sym_package] = { + .visible = true, + .named = true, + }, + [sym_option] = { + .visible = true, + .named = true, + }, + [sym_list] = { + .visible = true, + .named = true, + }, + [aux_sym_config_file_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_config_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_package_repeat1] = { + .visible = false, + .named = false, + }, +}; + +enum { + field_key = 1, + field_name = 2, + field_type = 3, + field_value = 4, +}; + +static const char * const ts_field_names[] = { + [0] = NULL, + [field_key] = "key", + [field_name] = "name", + [field_type] = "type", + [field_value] = "value", +}; + +static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { + [1] = {.index = 0, .length = 1}, + [2] = {.index = 1, .length = 2}, + [3] = {.index = 3, .length = 2}, +}; + +static const TSFieldMapEntry ts_field_map_entries[] = { + [0] = + {field_type, 1}, + [1] = + {field_name, 2}, + {field_type, 1}, + [3] = + {field_key, 1}, + {field_value, 2}, +}; + +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] = 3, + [12] = 4, + [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] = 4, + [26] = 3, + [27] = 27, + [28] = 28, + [29] = 29, + [30] = 30, + [31] = 31, + [32] = 28, + [33] = 27, + [34] = 28, + [35] = 27, + [36] = 30, + [37] = 29, + [38] = 30, + [39] = 29, +}; + +static inline bool anon_sym_DQUOTE_character_set_1(int32_t c) { + return (c < 8192 + ? (c < ' ' + ? (c < '\r' + ? (c >= '\t' && c <= '\n') + : c <= '\r') + : (c <= ' ' || (c < 5760 + ? c == 160 + : c <= 5760))) + : (c <= 8203 || (c < 12288 + ? (c < 8287 + ? c == 8239 + : c <= 8288) + : (c <= 12288 || c == 65279)))); +} + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(25); + if (lookahead == '"') ADVANCE(46); + if (lookahead == '#') ADVANCE(61); + if (lookahead == '\'') ADVANCE(47); + if (lookahead == 'c') ADVANCE(39); + if (lookahead == 'l') ADVANCE(33); + if (lookahead == 'o') ADVANCE(41); + if (lookahead == 'p') ADVANCE(26); + if (anon_sym_DQUOTE_character_set_1(lookahead)) SKIP(0) + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 1: + if (lookahead == '"') ADVANCE(46); + if (lookahead == '#') ADVANCE(61); + if (lookahead == '\'') ADVANCE(47); + if (anon_sym_DQUOTE_character_set_1(lookahead)) SKIP(1) + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 2: + if (lookahead == '"') ADVANCE(3); + if (lookahead == '#') ADVANCE(51); + if (lookahead == '\'') ADVANCE(4); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(2) + if (lookahead == 160 || + lookahead == 5760 || + (8192 <= lookahead && lookahead <= 8203) || + lookahead == 8239 || + lookahead == 8287 || + lookahead == 8288 || + lookahead == 12288 || + lookahead == 65279) ADVANCE(50); + if (lookahead != 0) ADVANCE(52); + END_STATE(); + case 3: + if (lookahead == '"') ADVANCE(48); + if (lookahead != 0 && + lookahead != '\\') ADVANCE(3); + END_STATE(); + case 4: + if (lookahead == '\'') ADVANCE(49); + if (lookahead != 0 && + lookahead != '\\') ADVANCE(4); + END_STATE(); + case 5: + if (lookahead == 'a') ADVANCE(7); + END_STATE(); + case 6: + if (lookahead == 'a') ADVANCE(11); + END_STATE(); + case 7: + if (lookahead == 'c') ADVANCE(15); + END_STATE(); + case 8: + if (lookahead == 'e') ADVANCE(55); + END_STATE(); + case 9: + if (lookahead == 'f') ADVANCE(13); + END_STATE(); + case 10: + if (lookahead == 'g') ADVANCE(53); + END_STATE(); + case 11: + if (lookahead == 'g') ADVANCE(8); + END_STATE(); + case 12: + if (lookahead == 'i') ADVANCE(21); + END_STATE(); + case 13: + if (lookahead == 'i') ADVANCE(10); + END_STATE(); + case 14: + if (lookahead == 'i') ADVANCE(19); + END_STATE(); + case 15: + if (lookahead == 'k') ADVANCE(6); + END_STATE(); + case 16: + if (lookahead == 'n') ADVANCE(9); + END_STATE(); + case 17: + if (lookahead == 'n') ADVANCE(57); + END_STATE(); + case 18: + if (lookahead == 'o') ADVANCE(16); + END_STATE(); + case 19: + if (lookahead == 'o') ADVANCE(17); + END_STATE(); + case 20: + if (lookahead == 'p') ADVANCE(23); + END_STATE(); + case 21: + if (lookahead == 's') ADVANCE(22); + END_STATE(); + case 22: + if (lookahead == 't') ADVANCE(59); + END_STATE(); + case 23: + if (lookahead == 't') ADVANCE(14); + END_STATE(); + case 24: + if (eof) ADVANCE(25); + if (lookahead == '#') ADVANCE(61); + if (lookahead == 'c') ADVANCE(18); + if (lookahead == 'l') ADVANCE(12); + if (lookahead == 'o') ADVANCE(20); + if (lookahead == 'p') ADVANCE(5); + if (anon_sym_DQUOTE_character_set_1(lookahead)) SKIP(24) + END_STATE(); + case 25: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 26: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'a') ADVANCE(28); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 27: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'a') ADVANCE(32); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 28: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'c') ADVANCE(36); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 29: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'e') ADVANCE(56); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 30: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'f') ADVANCE(34); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 31: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'g') ADVANCE(54); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 32: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'g') ADVANCE(29); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 33: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'i') ADVANCE(42); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 34: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'i') ADVANCE(31); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 35: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'i') ADVANCE(40); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 36: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'k') ADVANCE(27); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 37: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'n') ADVANCE(30); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 38: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'n') ADVANCE(58); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 39: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'o') ADVANCE(37); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 40: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'o') ADVANCE(38); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 41: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 'p') ADVANCE(44); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 42: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 's') ADVANCE(43); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 43: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 't') ADVANCE(60); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 44: + ACCEPT_TOKEN(sym__name_fragment); + if (lookahead == 't') ADVANCE(35); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 45: + ACCEPT_TOKEN(sym__name_fragment); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 46: + ACCEPT_TOKEN(anon_sym_DQUOTE); + END_STATE(); + case 47: + ACCEPT_TOKEN(anon_sym_SQUOTE); + END_STATE(); + case 48: + ACCEPT_TOKEN(aux_sym_string_token1); + END_STATE(); + case 49: + ACCEPT_TOKEN(aux_sym_string_token2); + END_STATE(); + case 50: + ACCEPT_TOKEN(aux_sym_string_token3); + if (lookahead == '#') ADVANCE(51); + if (lookahead == 160 || + lookahead == 5760 || + (8192 <= lookahead && lookahead <= 8203) || + lookahead == 8239 || + lookahead == 8287 || + lookahead == 8288 || + lookahead == 12288 || + lookahead == 65279) ADVANCE(50); + if (lookahead != 0 && + lookahead != '\t' && + lookahead != '\n' && + lookahead != '\r' && + lookahead != ' ' && + lookahead != '"' && + lookahead != '\'') ADVANCE(52); + END_STATE(); + case 51: + ACCEPT_TOKEN(aux_sym_string_token3); + if (lookahead == '\t' || + lookahead == '\r' || + lookahead == ' ' || + lookahead == '"' || + lookahead == '\'') ADVANCE(61); + if (lookahead != 0 && + lookahead != '\n') ADVANCE(51); + END_STATE(); + case 52: + ACCEPT_TOKEN(aux_sym_string_token3); + if (lookahead != 0 && + lookahead != '\t' && + lookahead != '\n' && + lookahead != '\r' && + lookahead != ' ' && + lookahead != '"' && + lookahead != '\'') ADVANCE(52); + END_STATE(); + case 53: + ACCEPT_TOKEN(anon_sym_config); + END_STATE(); + case 54: + ACCEPT_TOKEN(anon_sym_config); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 55: + ACCEPT_TOKEN(anon_sym_package); + END_STATE(); + case 56: + ACCEPT_TOKEN(anon_sym_package); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 57: + ACCEPT_TOKEN(anon_sym_option); + END_STATE(); + case 58: + ACCEPT_TOKEN(anon_sym_option); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 59: + ACCEPT_TOKEN(anon_sym_list); + END_STATE(); + case 60: + ACCEPT_TOKEN(anon_sym_list); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(45); + END_STATE(); + case 61: + ACCEPT_TOKEN(sym_comment); + if (lookahead != 0 && + lookahead != '\n') ADVANCE(61); + END_STATE(); + default: + return false; + } +} + +static const TSLexMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 24}, + [2] = {.lex_state = 0}, + [3] = {.lex_state = 0}, + [4] = {.lex_state = 0}, + [5] = {.lex_state = 24}, + [6] = {.lex_state = 24}, + [7] = {.lex_state = 24}, + [8] = {.lex_state = 24}, + [9] = {.lex_state = 24}, + [10] = {.lex_state = 24}, + [11] = {.lex_state = 24}, + [12] = {.lex_state = 24}, + [13] = {.lex_state = 24}, + [14] = {.lex_state = 24}, + [15] = {.lex_state = 24}, + [16] = {.lex_state = 24}, + [17] = {.lex_state = 24}, + [18] = {.lex_state = 24}, + [19] = {.lex_state = 2}, + [20] = {.lex_state = 1}, + [21] = {.lex_state = 2}, + [22] = {.lex_state = 1}, + [23] = {.lex_state = 1}, + [24] = {.lex_state = 1}, + [25] = {.lex_state = 2}, + [26] = {.lex_state = 2}, + [27] = {.lex_state = 0}, + [28] = {.lex_state = 0}, + [29] = {.lex_state = 1}, + [30] = {.lex_state = 1}, + [31] = {.lex_state = 0}, + [32] = {.lex_state = 0}, + [33] = {.lex_state = 0}, + [34] = {.lex_state = 0}, + [35] = {.lex_state = 0}, + [36] = {.lex_state = 1}, + [37] = {.lex_state = 1}, + [38] = {.lex_state = 1}, + [39] = {.lex_state = 1}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [0] = { + [ts_builtin_sym_end] = ACTIONS(1), + [sym__name_fragment] = ACTIONS(1), + [anon_sym_DQUOTE] = ACTIONS(1), + [anon_sym_SQUOTE] = ACTIONS(1), + [anon_sym_config] = ACTIONS(1), + [anon_sym_package] = ACTIONS(1), + [anon_sym_option] = ACTIONS(1), + [anon_sym_list] = ACTIONS(1), + [sym_comment] = ACTIONS(3), + }, + [1] = { + [sym_config_file] = STATE(31), + [sym_config] = STATE(9), + [sym_package] = STATE(9), + [aux_sym_config_file_repeat1] = STATE(9), + [ts_builtin_sym_end] = ACTIONS(5), + [anon_sym_config] = ACTIONS(7), + [anon_sym_package] = ACTIONS(9), + [sym_comment] = ACTIONS(3), + }, + [2] = { + [sym_name] = STATE(7), + [sym_option] = STATE(8), + [sym_list] = STATE(8), + [aux_sym_config_repeat1] = STATE(8), + [ts_builtin_sym_end] = ACTIONS(11), + [sym__name_fragment] = ACTIONS(13), + [anon_sym_DQUOTE] = ACTIONS(15), + [anon_sym_SQUOTE] = ACTIONS(17), + [anon_sym_config] = ACTIONS(19), + [anon_sym_package] = ACTIONS(19), + [anon_sym_option] = ACTIONS(21), + [anon_sym_list] = ACTIONS(23), + [sym_comment] = ACTIONS(3), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 3, + ACTIONS(3), 1, + sym_comment, + ACTIONS(25), 3, + ts_builtin_sym_end, + anon_sym_DQUOTE, + anon_sym_SQUOTE, + ACTIONS(27), 5, + sym__name_fragment, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [16] = 3, + ACTIONS(3), 1, + sym_comment, + ACTIONS(29), 3, + ts_builtin_sym_end, + anon_sym_DQUOTE, + anon_sym_SQUOTE, + ACTIONS(31), 5, + sym__name_fragment, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [32] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(35), 1, + anon_sym_option, + ACTIONS(38), 1, + anon_sym_list, + ACTIONS(33), 3, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + STATE(5), 3, + sym_option, + sym_list, + aux_sym_config_repeat1, + [52] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(43), 1, + anon_sym_option, + ACTIONS(45), 1, + anon_sym_list, + ACTIONS(41), 3, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + STATE(5), 3, + sym_option, + sym_list, + aux_sym_config_repeat1, + [72] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(43), 1, + anon_sym_option, + ACTIONS(45), 1, + anon_sym_list, + ACTIONS(47), 3, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + STATE(6), 3, + sym_option, + sym_list, + aux_sym_config_repeat1, + [92] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(43), 1, + anon_sym_option, + ACTIONS(45), 1, + anon_sym_list, + ACTIONS(49), 3, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + STATE(5), 3, + sym_option, + sym_list, + aux_sym_config_repeat1, + [112] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(7), 1, + anon_sym_config, + ACTIONS(9), 1, + anon_sym_package, + ACTIONS(51), 1, + ts_builtin_sym_end, + STATE(10), 3, + sym_config, + sym_package, + aux_sym_config_file_repeat1, + [130] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(53), 1, + ts_builtin_sym_end, + ACTIONS(55), 1, + anon_sym_config, + ACTIONS(58), 1, + anon_sym_package, + STATE(10), 3, + sym_config, + sym_package, + aux_sym_config_file_repeat1, + [148] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(25), 5, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [159] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(29), 5, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [170] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(61), 5, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [181] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(63), 5, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [192] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(65), 5, + ts_builtin_sym_end, + anon_sym_config, + anon_sym_package, + anon_sym_option, + anon_sym_list, + [203] = 4, + ACTIONS(3), 1, + sym_comment, + ACTIONS(7), 1, + anon_sym_config, + ACTIONS(67), 2, + ts_builtin_sym_end, + anon_sym_package, + STATE(18), 2, + sym_config, + aux_sym_package_repeat1, + [218] = 4, + ACTIONS(3), 1, + sym_comment, + ACTIONS(71), 1, + anon_sym_config, + ACTIONS(69), 2, + ts_builtin_sym_end, + anon_sym_package, + STATE(17), 2, + sym_config, + aux_sym_package_repeat1, + [233] = 4, + ACTIONS(3), 1, + sym_comment, + ACTIONS(7), 1, + anon_sym_config, + ACTIONS(74), 2, + ts_builtin_sym_end, + anon_sym_package, + STATE(17), 2, + sym_config, + aux_sym_package_repeat1, + [248] = 3, + ACTIONS(78), 1, + sym_comment, + STATE(14), 1, + sym_string, + ACTIONS(76), 3, + aux_sym_string_token1, + aux_sym_string_token2, + aux_sym_string_token3, + [260] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(80), 1, + sym__name_fragment, + ACTIONS(82), 1, + anon_sym_DQUOTE, + ACTIONS(84), 1, + anon_sym_SQUOTE, + STATE(2), 1, + sym_name, + [276] = 3, + ACTIONS(78), 1, + sym_comment, + STATE(13), 1, + sym_string, + ACTIONS(76), 3, + aux_sym_string_token1, + aux_sym_string_token2, + aux_sym_string_token3, + [288] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(86), 1, + sym__name_fragment, + ACTIONS(88), 1, + anon_sym_DQUOTE, + ACTIONS(90), 1, + anon_sym_SQUOTE, + STATE(21), 1, + sym_name, + [304] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(86), 1, + sym__name_fragment, + ACTIONS(88), 1, + anon_sym_DQUOTE, + ACTIONS(90), 1, + anon_sym_SQUOTE, + STATE(19), 1, + sym_name, + [320] = 5, + ACTIONS(3), 1, + sym_comment, + ACTIONS(15), 1, + anon_sym_DQUOTE, + ACTIONS(17), 1, + anon_sym_SQUOTE, + ACTIONS(92), 1, + sym__name_fragment, + STATE(16), 1, + sym_name, + [336] = 2, + ACTIONS(78), 1, + sym_comment, + ACTIONS(31), 3, + aux_sym_string_token1, + aux_sym_string_token2, + aux_sym_string_token3, + [345] = 2, + ACTIONS(78), 1, + sym_comment, + ACTIONS(27), 3, + aux_sym_string_token1, + aux_sym_string_token2, + aux_sym_string_token3, + [354] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(94), 1, + anon_sym_SQUOTE, + [361] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(94), 1, + anon_sym_DQUOTE, + [368] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(96), 1, + sym__name_fragment, + [375] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(98), 1, + sym__name_fragment, + [382] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(100), 1, + ts_builtin_sym_end, + [389] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(102), 1, + anon_sym_DQUOTE, + [396] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(102), 1, + anon_sym_SQUOTE, + [403] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(104), 1, + anon_sym_DQUOTE, + [410] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(104), 1, + anon_sym_SQUOTE, + [417] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(106), 1, + sym__name_fragment, + [424] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(108), 1, + sym__name_fragment, + [431] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(110), 1, + sym__name_fragment, + [438] = 2, + ACTIONS(3), 1, + sym_comment, + ACTIONS(112), 1, + sym__name_fragment, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(3)] = 0, + [SMALL_STATE(4)] = 16, + [SMALL_STATE(5)] = 32, + [SMALL_STATE(6)] = 52, + [SMALL_STATE(7)] = 72, + [SMALL_STATE(8)] = 92, + [SMALL_STATE(9)] = 112, + [SMALL_STATE(10)] = 130, + [SMALL_STATE(11)] = 148, + [SMALL_STATE(12)] = 159, + [SMALL_STATE(13)] = 170, + [SMALL_STATE(14)] = 181, + [SMALL_STATE(15)] = 192, + [SMALL_STATE(16)] = 203, + [SMALL_STATE(17)] = 218, + [SMALL_STATE(18)] = 233, + [SMALL_STATE(19)] = 248, + [SMALL_STATE(20)] = 260, + [SMALL_STATE(21)] = 276, + [SMALL_STATE(22)] = 288, + [SMALL_STATE(23)] = 304, + [SMALL_STATE(24)] = 320, + [SMALL_STATE(25)] = 336, + [SMALL_STATE(26)] = 345, + [SMALL_STATE(27)] = 354, + [SMALL_STATE(28)] = 361, + [SMALL_STATE(29)] = 368, + [SMALL_STATE(30)] = 375, + [SMALL_STATE(31)] = 382, + [SMALL_STATE(32)] = 389, + [SMALL_STATE(33)] = 396, + [SMALL_STATE(34)] = 403, + [SMALL_STATE(35)] = 410, + [SMALL_STATE(36)] = 417, + [SMALL_STATE(37)] = 424, + [SMALL_STATE(38)] = 431, + [SMALL_STATE(39)] = 438, +}; + +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}}, SHIFT_EXTRA(), + [5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_config_file, 0), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), + [11] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_config, 2, .production_id = 1), + [13] = {.entry = {.count = 1, .reusable = false}}, SHIFT(12), + [15] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36), + [17] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), + [19] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_config, 2, .production_id = 1), + [21] = {.entry = {.count = 1, .reusable = false}}, SHIFT(23), + [23] = {.entry = {.count = 1, .reusable = false}}, SHIFT(22), + [25] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_name, 3), + [27] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_name, 3), + [29] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_name, 1), + [31] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_name, 1), + [33] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_config_repeat1, 2), + [35] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_config_repeat1, 2), SHIFT_REPEAT(23), + [38] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_config_repeat1, 2), SHIFT_REPEAT(22), + [41] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_config, 4, .production_id = 2), + [43] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), + [45] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), + [47] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_config, 3, .production_id = 2), + [49] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_config, 3, .production_id = 1), + [51] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_config_file, 1), + [53] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_config_file_repeat1, 2), + [55] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_config_file_repeat1, 2), SHIFT_REPEAT(20), + [58] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_config_file_repeat1, 2), SHIFT_REPEAT(24), + [61] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_list, 3, .production_id = 3), + [63] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_option, 3, .production_id = 3), + [65] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 1), + [67] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_package, 2), + [69] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_package_repeat1, 2), + [71] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_package_repeat1, 2), SHIFT_REPEAT(20), + [74] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_package, 3), + [76] = {.entry = {.count = 1, .reusable = false}}, SHIFT(15), + [78] = {.entry = {.count = 1, .reusable = false}}, SHIFT_EXTRA(), + [80] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [82] = {.entry = {.count = 1, .reusable = true}}, SHIFT(30), + [84] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), + [86] = {.entry = {.count = 1, .reusable = true}}, SHIFT(25), + [88] = {.entry = {.count = 1, .reusable = true}}, SHIFT(38), + [90] = {.entry = {.count = 1, .reusable = true}}, SHIFT(39), + [92] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [94] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), + [96] = {.entry = {.count = 1, .reusable = true}}, SHIFT(27), + [98] = {.entry = {.count = 1, .reusable = true}}, SHIFT(28), + [100] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [102] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [104] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26), + [106] = {.entry = {.count = 1, .reusable = true}}, SHIFT(32), + [108] = {.entry = {.count = 1, .reusable = true}}, SHIFT(33), + [110] = {.entry = {.count = 1, .reusable = true}}, SHIFT(34), + [112] = {.entry = {.count = 1, .reusable = true}}, SHIFT(35), +}; + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef _WIN32 +#define extern __declspec(dllexport) +#endif + +extern const TSLanguage *tree_sitter_uci(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_