diff options
Diffstat (limited to '')
26 files changed, 887 insertions, 3109 deletions
diff --git a/tree-sitter-yts/.editorconfig b/tree-sitter-yts/.editorconfig index 9975ff2..ff17b12 100644 --- a/tree-sitter-yts/.editorconfig +++ b/tree-sitter-yts/.editorconfig @@ -1,24 +1,50 @@ -# yt - A fully featured command line YouTube client -# -# Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This file is part of Yt. -# -# You should have received a copy of the License along with this program. -# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +root = true -# for testing purposes, the corpus may have trailing whitespace -# and may have mixed EOL. -# Still want a final newline though, as that makes no semantic difference. -[corpus/*] -trim_trailing_whitespace = false -end_of_line = unset +[*] +charset = utf-8 -[**.{js,json,cc,css}] +[*.{json,toml,yml,gyp,xml}] indent_style = space indent_size = 2 -# tree-sitter generate emits json with no trailing newline -[src/node-types.json] -insert_final_newline = false +[*.{js,ts}] +indent_style = space +indent_size = 2 + +[*.scm] +indent_style = space +indent_size = 2 + +[*.{c,cc,h}] +indent_style = space +indent_size = 4 + +[*.rs] +indent_style = space +indent_size = 4 + +[*.{py,pyi}] +indent_style = space +indent_size = 4 + +[*.swift] +indent_style = space +indent_size = 4 + +[*.java] +indent_style = space +indent_size = 4 + +[*.go] +indent_style = tab +indent_size = 8 + +[Makefile] +indent_style = tab +indent_size = 8 + +[parser.c] +indent_size = 2 + +[{alloc,array,parser}.h] +indent_size = 2 diff --git a/tree-sitter-yts/.gitattributes b/tree-sitter-yts/.gitattributes new file mode 100644 index 0000000..027ac70 --- /dev/null +++ b/tree-sitter-yts/.gitattributes @@ -0,0 +1,46 @@ +* text=auto eol=lf + +# Generated source files +src/*.json linguist-generated +src/parser.c linguist-generated +src/tree_sitter/* linguist-generated + +# C bindings +bindings/c/** linguist-generated +CMakeLists.txt linguist-generated +Makefile linguist-generated + +# Rust bindings +bindings/rust/* linguist-generated +Cargo.toml linguist-generated +Cargo.lock linguist-generated + +# Node.js bindings +bindings/node/* linguist-generated +binding.gyp linguist-generated +package.json linguist-generated +package-lock.json linguist-generated + +# Python bindings +bindings/python/** linguist-generated +setup.py linguist-generated +pyproject.toml linguist-generated + +# Go bindings +bindings/go/* linguist-generated +go.mod linguist-generated +go.sum linguist-generated + +# Swift bindings +bindings/swift/** linguist-generated +Package.swift linguist-generated +Package.resolved linguist-generated + +# Zig bindings +bindings/zig/* linguist-generated +build.zig linguist-generated +build.zig.zon linguist-generated + +# Java bindings +pom.xml linguist-generated +bindings/java/** linguist-generated diff --git a/tree-sitter-yts/.gitignore b/tree-sitter-yts/.gitignore index 88a62ca..7c0cb7f 100644 --- a/tree-sitter-yts/.gitignore +++ b/tree-sitter-yts/.gitignore @@ -1,11 +1,48 @@ -# yt - A fully featured command line YouTube client -# -# Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This file is part of Yt. -# -# You should have received a copy of the License along with this program. -# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +# Rust artifacts +target/ -/node_modules +# Node artifacts +build/ +prebuilds/ +node_modules/ + +# Swift artifacts +.build/ + +# Go artifacts +_obj/ + +# Python artifacts +.venv/ +dist/ +*.egg-info +*.whl + +# C artifacts +*.a +*.so +*.so.* +*.dylib +*.dll +*.pc +*.exp +*.lib + +# Zig artifacts +.zig-cache/ +zig-cache/ +zig-out/ + +# Example dirs +/examples/*/ + +# Grammar volatiles +*.wasm +*.obj +*.o + +# Archives +*.tar.gz +*.tgz +*.zip +*.jar diff --git a/tree-sitter-yts/Cargo.toml b/tree-sitter-yts/Cargo.toml index 1872f18..a6c259c 100644 --- a/tree-sitter-yts/Cargo.toml +++ b/tree-sitter-yts/Cargo.toml @@ -1,31 +1,34 @@ -# yt - A fully featured command line YouTube client -# -# Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This file is part of Yt. -# -# You should have received a copy of the License along with this program. -# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - [package] name = "tree-sitter-yts" -description = "yts grammar for the tree-sitter parsing library" -version = "0.0.1" -keywords = ["incremental", "parsing", "yts"] -categories = ["parsing", "text-editors"] -repository = "https://github.com/tree-sitter/tree-sitter-yts" -edition = "2018" -license = "MIT" +description = "Parser for yt's selection language" +version = "0.1.0" +authors = ["Benedikt Peetz <benedikt.peetz@b-peetz.de>"] +license = "GPL-3-or-later" +readme = "README.md" +keywords = ["incremental", "parsing", "tree-sitter", "yts"] +categories = ["parser-implementations", "parsing", "text-editors"] +repository = "https://git.foss-syndicate.org/bpeetz/clients/yt" +edition = "2021" +autoexamples = false build = "bindings/rust/build.rs" -include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] +include = [ + "bindings/rust/*", + "grammar.js", + "queries/*", + "src/*", + "tree-sitter.json", + "/LICENSE", +] [lib] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "~0.20.10" +tree-sitter-language = "0.1" [build-dependencies] -cc = "1.0" +cc = "1.2" + +[dev-dependencies] +tree-sitter = "0.26.8" diff --git a/tree-sitter-yts/binding.gyp b/tree-sitter-yts/binding.gyp deleted file mode 100644 index b05038b..0000000 --- a/tree-sitter-yts/binding.gyp +++ /dev/null @@ -1,19 +0,0 @@ -{ - "targets": [ - { - "target_name": "tree_sitter_yts_binding", - "include_dirs": [ - "<!(node -e \"require('nan')\")", - "src" - ], - "sources": [ - "bindings/node/binding.cc", - "src/parser.c", - # If your language uses an external scanner, add it here. - ], - "cflags_c": [ - "-std=c99", - ] - } - ] -} diff --git a/tree-sitter-yts/binding.gyp.license b/tree-sitter-yts/binding.gyp.license deleted file mode 100644 index d4d410f..0000000 --- a/tree-sitter-yts/binding.gyp.license +++ /dev/null @@ -1,9 +0,0 @@ -yt - A fully featured command line YouTube client - -Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of Yt. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/tree-sitter-yts/bindings/node/binding.cc b/tree-sitter-yts/bindings/node/binding.cc deleted file mode 100644 index fdf44ff..0000000 --- a/tree-sitter-yts/bindings/node/binding.cc +++ /dev/null @@ -1,43 +0,0 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - -#include "nan.h" -#include "tree_sitter/parser.h" -#include <node.h> - -using namespace v8; - -extern "C" TSLanguage *tree_sitter_yts (); - -namespace -{ - -NAN_METHOD (New) {} - -void -Init (Local<Object> exports, Local<Object> module) -{ - Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate> (New); - tpl->SetClassName (Nan::New ("Language").ToLocalChecked ()); - tpl->InstanceTemplate ()->SetInternalFieldCount (1); - - Local<Function> constructor = Nan::GetFunction (tpl).ToLocalChecked (); - Local<Object> instance - = constructor->NewInstance (Nan::GetCurrentContext ()).ToLocalChecked (); - Nan::SetInternalFieldPointer (instance, 0, tree_sitter_yts ()); - - Nan::Set (instance, Nan::New ("name").ToLocalChecked (), - Nan::New ("yts").ToLocalChecked ()); - Nan::Set (module, Nan::New ("exports").ToLocalChecked (), instance); -} - -NODE_MODULE (tree_sitter_yts_binding, Init) - -} // namespace diff --git a/tree-sitter-yts/bindings/node/index.js b/tree-sitter-yts/bindings/node/index.js deleted file mode 100644 index 580bda0..0000000 --- a/tree-sitter-yts/bindings/node/index.js +++ /dev/null @@ -1,29 +0,0 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - -try { - module.exports = require("../../build/Release/tree_sitter_yts_binding"); -} catch (error1) { - if (error1.code !== "MODULE_NOT_FOUND") { - throw error1; - } - try { - module.exports = require("../../build/Debug/tree_sitter_yts_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/tree-sitter-yts/bindings/rust/build.rs b/tree-sitter-yts/bindings/rust/build.rs index 075dc92..95250d7 100644 --- a/tree-sitter-yts/bindings/rust/build.rs +++ b/tree-sitter-yts/bindings/rust/build.rs @@ -1,50 +1,56 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - 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); + c_config.std("c11").include(src_dir); - // If your language uses an external scanner written in C, - // then include this block of code: + #[cfg(target_env = "msvc")] + c_config.flag("-utf-8"); - /* - let scanner_path = src_dir.join("scanner.c"); - c_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); - */ + if std::env::var("TARGET").unwrap() == "wasm32-unknown-unknown" { + let Ok(wasm_headers) = std::env::var("DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS") else { + panic!("Environment variable DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS must be set by the language crate"); + }; + let Ok(wasm_src) = + std::env::var("DEP_TREE_SITTER_LANGUAGE_WASM_SRC").map(std::path::PathBuf::from) + else { + panic!("Environment variable DEP_TREE_SITTER_LANGUAGE_WASM_SRC must be set by the language crate"); + }; + + c_config.include(&wasm_headers); + c_config.files([ + wasm_src.join("stdio.c"), + wasm_src.join("stdlib.c"), + wasm_src.join("string.c"), + ]); + } - c_config.compile("parser"); + let parser_path = src_dir.join("parser.c"); + c_config.file(&parser_path); 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 scanner_path = src_dir.join("scanner.c"); + if scanner_path.exists() { + c_config.file(&scanner_path); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + } + + c_config.compile("tree-sitter-yts"); - /* - 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()); - */ + println!("cargo:rustc-check-cfg=cfg(with_highlights_query)"); + if !"queries/highlights.scm".is_empty() && std::path::Path::new("queries/highlights.scm").exists() { + println!("cargo:rustc-cfg=with_highlights_query"); + } + println!("cargo:rustc-check-cfg=cfg(with_injections_query)"); + if !"queries/injections.scm".is_empty() && std::path::Path::new("queries/injections.scm").exists() { + println!("cargo:rustc-cfg=with_injections_query"); + } + println!("cargo:rustc-check-cfg=cfg(with_locals_query)"); + if !"queries/locals.scm".is_empty() && std::path::Path::new("queries/locals.scm").exists() { + println!("cargo:rustc-cfg=with_locals_query"); + } + println!("cargo:rustc-check-cfg=cfg(with_tags_query)"); + if !"queries/tags.scm".is_empty() && std::path::Path::new("queries/tags.scm").exists() { + println!("cargo:rustc-cfg=with_tags_query"); + } } diff --git a/tree-sitter-yts/bindings/rust/lib.rs b/tree-sitter-yts/bindings/rust/lib.rs index 0880238..35f14ce 100644 --- a/tree-sitter-yts/bindings/rust/lib.rs +++ b/tree-sitter-yts/bindings/rust/lib.rs @@ -1,54 +1,52 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - -//! This crate provides yts language support for the [tree-sitter][] parsing library. +//! This crate provides YTS 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: +//! Typically, you will use the [`LANGUAGE`] constant to add this language to a +//! tree-sitter [`Parser`], and then use the parser to parse some code: //! //! ``` -//! let code = ""; +//! let code = r#" +//! "#; //! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_yts::language()).expect("Error loading yts grammar"); +//! let language = tree_sitter_YTS::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading YTS parser"); //! let tree = parser.parse(code, None).unwrap(); +//! assert!(!tree.root_node().has_error()); //! ``` //! -//! [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 +//! [`Parser`]: https://docs.rs/tree-sitter/0.26.8/tree_sitter/struct.Parser.html //! [tree-sitter]: https://tree-sitter.github.io/ -use tree_sitter::Language; +use tree_sitter_language::LanguageFn; extern "C" { - fn tree_sitter_yts() -> Language; + fn tree_sitter_YTS() -> *const (); } -/// 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_yts() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_YTS) }; -/// The content of the [`node-types.json`][] file for this grammar. +/// 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"); +/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types +pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); + +#[cfg(with_highlights_query)] +/// The syntax highlighting query for this grammar. +pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); + +#[cfg(with_injections_query)] +/// The language injection query for this grammar. +pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); -// Uncomment these to include any queries that this grammar contains +#[cfg(with_locals_query)] +/// The local variable query for this grammar. +pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); -// 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(with_tags_query)] +/// The symbol tagging query for this grammar. +pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); #[cfg(test)] mod tests { @@ -56,7 +54,7 @@ mod tests { fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser - .set_language(super::language()) - .expect("Error loading yts language"); + .set_language(&super::LANGUAGE.into()) + .expect("Error loading YTS parser"); } } diff --git a/tree-sitter-yts/grammar.js b/tree-sitter-yts/grammar.js index 7576228..2b36254 100644 --- a/tree-sitter-yts/grammar.js +++ b/tree-sitter-yts/grammar.js @@ -1,73 +1,17 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +/** + * @file Parser for yt's selection language + * @author Benedikt Peetz <benedikt.peetz@b-peetz.de> + * @license GPL-3-or-later + */ -module.exports = grammar({ +/// <reference types="tree-sitter-cli/dsl" /> +// @ts-check + +export default grammar({ name: "yts", rules: { - source_file: ($) => repeat(choice($.line, $.comment)), - line: ($) => - seq( - $.command, - repeat($.flag), - $.id, - $.title, - $.date, - $.author, - $.duration, - $.url, - "\n", - ), - - command: ($) => - choice( - "pick", - "p", - "watch", - "w", - "watched", - "wd", - "add", - "a", - "drop", - "d", - "url", - "u", - ), - flag: ($) => - choice( - /-\w [^\s]+/, - /-\w '[^']*'/, - /-\w "[^"]*"/, - /-\w=[^\s]+/, - /-\w='[^']*'/, - /-\w="[^"]*"/, - - /--\w[\w-]+ [^\s]+/, - /--\w[\w-]+ '[^']*'/, - /--\w[\w-]+ "[^"]*"/, - /--\w[\w-]+=[^\s]+/, - /--\w[\w-]+='[^']*'/, - /--\w[\w-]+="[^"]*"/, - ), - id: ($) => /[a-z0-9]+/, - title: ($) => seq($._q, /[^"]+/, $._q), - date: ($) => - seq($._q, choice("[No release date]", /\d{4}-\d{2}-\d{2}/), $._q), - author: ($) => seq($._q, choice("[No author]", /[^"]+/), $._q), - duration: ($) => - seq($._q, seq(choice("[No duration]", /\d+m \d+s/, /\d+h \d+m/)), $._q), - url: ($) => seq($._q, /[^"]+/, $._q), - comment: ($) => /#.*/, - _q: ($) => $.quote, - quote: ($) => /"/, - }, - extras: ($) => [/\s/], + // TODO: add the actual grammar rules + source_file: $ => "hello" + } }); diff --git a/tree-sitter-yts/highlight_sample.yts b/tree-sitter-yts/highlight_sample.yts deleted file mode 100644 index 7f75852..0000000 --- a/tree-sitter-yts/highlight_sample.yts +++ /dev/null @@ -1,7 +0,0 @@ -pick 6a21 "Name" "2024-01-17" "A" "0h 00m" "url" -pick 6z81 "Name2" "2024-01-16" "A2" "0h 00m" "url2" -pick 6b84 "Name3" "2024-01-16" "A3" "0h 00m" "url3" -pick 6f06 "Name4" "2024-01-16" "A4" "299h 36m" "url4" -watch --priority="-100" --speed 1 6z21 "Name" "2024-01-17" "A" "0m 0s" "url" -watch -s 2 -l 'en,gr,fr' 61f1 "Name2" "2024-01-16" "A2" "0m 0s" "url" -watch -s=2 -l='en,gr,fr' 61f1 "Name2" "2024-01-16" "A2" "0m 0s" "url" diff --git a/tree-sitter-yts/highlight_sample.yts.license b/tree-sitter-yts/highlight_sample.yts.license deleted file mode 100644 index d4d410f..0000000 --- a/tree-sitter-yts/highlight_sample.yts.license +++ /dev/null @@ -1,9 +0,0 @@ -yt - A fully featured command line YouTube client - -Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of Yt. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/tree-sitter-yts/package.json b/tree-sitter-yts/package.json index 5bd57c0..43eb988 100644 --- a/tree-sitter-yts/package.json +++ b/tree-sitter-yts/package.json @@ -1,19 +1,56 @@ { "name": "tree-sitter-yts", - "version": "0.0.1", - "description": "yts grammar for tree-sitter", + "version": "0.1.0", + "description": "Parser for yt's selection language", + "type": "module", + "repository": { + "type": "git", + "url": "git+https://git.foss-syndicate.org/bpeetz/clients/yt.git" + }, + "license": "GPL-3-or-later", + "author": { + "name": "Benedikt Peetz", + "email": "benedikt.peetz@b-peetz.de" + }, "main": "bindings/node", + "types": "bindings/node", "keywords": [ + "incremental", "parsing", - "incremental" + "tree-sitter", + "yts" + ], + "files": [ + "grammar.js", + "tree-sitter.json", + "binding.gyp", + "prebuilds/**", + "bindings/node/*", + "queries/*", + "src/**", + "*.wasm" ], "dependencies": { - "nan": "^2.12.1" + "node-addon-api": "^8.5.0", + "node-gyp-build": "^4.8.4" }, "devDependencies": { - "tree-sitter-cli": "^0.20.8" + "prebuildify": "^6.0.1", + "tree-sitter": "^0.25.0", + "tree-sitter-cli": "^0.26.8" + }, + "peerDependencies": { + "tree-sitter": "^0.25.0" + }, + "peerDependenciesMeta": { + "tree-sitter": { + "optional": true + } }, "scripts": { - "test": "tree-sitter test" + "install": "node-gyp-build", + "prestart": "tree-sitter build --wasm", + "start": "tree-sitter playground", + "test": "node --test bindings/node/*_test.js" } } diff --git a/tree-sitter-yts/package.json.license b/tree-sitter-yts/package.json.license deleted file mode 100644 index d4d410f..0000000 --- a/tree-sitter-yts/package.json.license +++ /dev/null @@ -1,9 +0,0 @@ -yt - A fully featured command line YouTube client - -Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of Yt. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/tree-sitter-yts/package.nix b/tree-sitter-yts/package.nix index 3a0f8f6..6582d64 100644 --- a/tree-sitter-yts/package.nix +++ b/tree-sitter-yts/package.nix @@ -8,60 +8,11 @@ # You should have received a copy of the License along with this program. # If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. { - stdenv, - nodejs, tree-sitter, - lib, }: -# # Build a parser grammar and put the resulting shared object in `$out/parser` -# { -# # language name -# language ? "yts", -# version ? "1.0.0", -# src ? ./., -# location ? null, -# generate ? false, -# ... -# } @ args: -stdenv.mkDerivation { - pname = "yts-grammar"; - version = "1.0.0"; +tree-sitter.buildGrammar { + language = "yts"; + version = "0.1.0"; src = ./.; - - nativeBuildInputs = [nodejs tree-sitter]; - - CFLAGS = ["-Isrc" "-O2"]; - CXXFLAGS = ["-Isrc" "-O2"]; - - stripDebugList = ["parser"]; - - configurePhase = '' - tree-sitter generate - ''; - - # When both scanner.{c,cc} exist, we should not link both since they may be the same but in - # different languages. Just randomly prefer C++ if that happens. - buildPhase = '' - runHook preBuild - if [[ -e src/scanner.cc ]]; then - $CXX -fPIC -c src/scanner.cc -o scanner.o $CXXFLAGS - elif [[ -e src/scanner.c ]]; then - $CC -fPIC -c src/scanner.c -o scanner.o $CFLAGS - fi - $CC -fPIC -c src/parser.c -o parser.o $CFLAGS - rm -rf parser - $CXX -shared -o parser *.o - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - mkdir $out - mv parser $out/ - if [[ -d queries ]]; then - cp -r queries $out - fi - runHook postInstall - ''; } diff --git a/tree-sitter-yts/src/grammar.json b/tree-sitter-yts/src/grammar.json index f2f337c..b979e83 100644 --- a/tree-sitter-yts/src/grammar.json +++ b/tree-sitter-yts/src/grammar.json @@ -3,307 +3,8 @@ "name": "yts", "rules": { "source_file": { - "type": "REPEAT", - "content": { - "type": "CHOICE", - "members": [ - { - "type": "SYMBOL", - "name": "line" - }, - { - "type": "SYMBOL", - "name": "comment" - } - ] - } - }, - "line": { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "command" - }, - { - "type": "REPEAT", - "content": { - "type": "SYMBOL", - "name": "flag" - } - }, - { - "type": "SYMBOL", - "name": "id" - }, - { - "type": "SYMBOL", - "name": "title" - }, - { - "type": "SYMBOL", - "name": "date" - }, - { - "type": "SYMBOL", - "name": "author" - }, - { - "type": "SYMBOL", - "name": "duration" - }, - { - "type": "SYMBOL", - "name": "url" - }, - { - "type": "STRING", - "value": "\n" - } - ] - }, - "command": { - "type": "CHOICE", - "members": [ - { - "type": "STRING", - "value": "pick" - }, - { - "type": "STRING", - "value": "p" - }, - { - "type": "STRING", - "value": "watch" - }, - { - "type": "STRING", - "value": "w" - }, - { - "type": "STRING", - "value": "watched" - }, - { - "type": "STRING", - "value": "wd" - }, - { - "type": "STRING", - "value": "add" - }, - { - "type": "STRING", - "value": "a" - }, - { - "type": "STRING", - "value": "drop" - }, - { - "type": "STRING", - "value": "d" - }, - { - "type": "STRING", - "value": "url" - }, - { - "type": "STRING", - "value": "u" - } - ] - }, - "flag": { - "type": "CHOICE", - "members": [ - { - "type": "PATTERN", - "value": "-\\w [^\\s]+" - }, - { - "type": "PATTERN", - "value": "-\\w '[^']*'" - }, - { - "type": "PATTERN", - "value": "-\\w \"[^\"]*\"" - }, - { - "type": "PATTERN", - "value": "-\\w=[^\\s]+" - }, - { - "type": "PATTERN", - "value": "-\\w='[^']*'" - }, - { - "type": "PATTERN", - "value": "-\\w=\"[^\"]*\"" - }, - { - "type": "PATTERN", - "value": "--\\w[\\w-]+ [^\\s]+" - }, - { - "type": "PATTERN", - "value": "--\\w[\\w-]+ '[^']*'" - }, - { - "type": "PATTERN", - "value": "--\\w[\\w-]+ \"[^\"]*\"" - }, - { - "type": "PATTERN", - "value": "--\\w[\\w-]+=[^\\s]+" - }, - { - "type": "PATTERN", - "value": "--\\w[\\w-]+='[^']*'" - }, - { - "type": "PATTERN", - "value": "--\\w[\\w-]+=\"[^\"]*\"" - } - ] - }, - "id": { - "type": "PATTERN", - "value": "[a-z0-9]+" - }, - "title": { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "_q" - }, - { - "type": "PATTERN", - "value": "[^\"]+" - }, - { - "type": "SYMBOL", - "name": "_q" - } - ] - }, - "date": { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "_q" - }, - { - "type": "CHOICE", - "members": [ - { - "type": "STRING", - "value": "[No release date]" - }, - { - "type": "PATTERN", - "value": "\\d{4}-\\d{2}-\\d{2}" - } - ] - }, - { - "type": "SYMBOL", - "name": "_q" - } - ] - }, - "author": { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "_q" - }, - { - "type": "CHOICE", - "members": [ - { - "type": "STRING", - "value": "[No author]" - }, - { - "type": "PATTERN", - "value": "[^\"]+" - } - ] - }, - { - "type": "SYMBOL", - "name": "_q" - } - ] - }, - "duration": { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "_q" - }, - { - "type": "SEQ", - "members": [ - { - "type": "CHOICE", - "members": [ - { - "type": "STRING", - "value": "[No duration]" - }, - { - "type": "PATTERN", - "value": "\\d+m \\d+s" - }, - { - "type": "PATTERN", - "value": "\\d+h \\d+m" - } - ] - } - ] - }, - { - "type": "SYMBOL", - "name": "_q" - } - ] - }, - "url": { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "_q" - }, - { - "type": "PATTERN", - "value": "[^\"]+" - }, - { - "type": "SYMBOL", - "name": "_q" - } - ] - }, - "comment": { - "type": "PATTERN", - "value": "#.*" - }, - "_q": { - "type": "SYMBOL", - "name": "quote" - }, - "quote": { - "type": "PATTERN", - "value": "\"" + "type": "STRING", + "value": "hello" } }, "extras": [ @@ -316,5 +17,6 @@ "precedences": [], "externals": [], "inline": [], - "supertypes": [] -} + "supertypes": [], + "reserved": {} +}
\ No newline at end of file diff --git a/tree-sitter-yts/src/grammar.json.license b/tree-sitter-yts/src/grammar.json.license deleted file mode 100644 index d4d410f..0000000 --- a/tree-sitter-yts/src/grammar.json.license +++ /dev/null @@ -1,9 +0,0 @@ -yt - A fully featured command line YouTube client - -Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of Yt. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/tree-sitter-yts/src/node-types.json b/tree-sitter-yts/src/node-types.json index 809eb38..cd69f6e 100644 --- a/tree-sitter-yts/src/node-types.json +++ b/tree-sitter-yts/src/node-types.json @@ -1,226 +1,12 @@ [ { - "type": "author", - "named": true, - "fields": {}, - "children": { - "multiple": true, - "required": true, - "types": [ - { - "type": "quote", - "named": true - } - ] - } - }, - { - "type": "command", - "named": true, - "fields": {} - }, - { - "type": "date", - "named": true, - "fields": {}, - "children": { - "multiple": true, - "required": true, - "types": [ - { - "type": "quote", - "named": true - } - ] - } - }, - { - "type": "duration", - "named": true, - "fields": {}, - "children": { - "multiple": true, - "required": true, - "types": [ - { - "type": "quote", - "named": true - } - ] - } - }, - { - "type": "flag", - "named": true, - "fields": {} - }, - { - "type": "line", - "named": true, - "fields": {}, - "children": { - "multiple": true, - "required": true, - "types": [ - { - "type": "author", - "named": true - }, - { - "type": "command", - "named": true - }, - { - "type": "date", - "named": true - }, - { - "type": "duration", - "named": true - }, - { - "type": "flag", - "named": true - }, - { - "type": "id", - "named": true - }, - { - "type": "title", - "named": true - }, - { - "type": "url", - "named": true - } - ] - } - }, - { "type": "source_file", "named": true, "root": true, - "fields": {}, - "children": { - "multiple": true, - "required": false, - "types": [ - { - "type": "comment", - "named": true - }, - { - "type": "line", - "named": true - } - ] - } - }, - { - "type": "title", - "named": true, - "fields": {}, - "children": { - "multiple": true, - "required": true, - "types": [ - { - "type": "quote", - "named": true - } - ] - } - }, - { - "type": "url", - "named": true, - "fields": {}, - "children": { - "multiple": true, - "required": true, - "types": [ - { - "type": "quote", - "named": true - } - ] - } - }, - { - "type": "\n", - "named": false - }, - { - "type": "[No author]", - "named": false - }, - { - "type": "[No duration]", - "named": false - }, - { - "type": "[No release date]", - "named": false - }, - { - "type": "a", - "named": false - }, - { - "type": "add", - "named": false - }, - { - "type": "comment", - "named": true - }, - { - "type": "d", - "named": false - }, - { - "type": "drop", - "named": false - }, - { - "type": "id", - "named": true - }, - { - "type": "p", - "named": false - }, - { - "type": "pick", - "named": false - }, - { - "type": "quote", - "named": true - }, - { - "type": "u", - "named": false - }, - { - "type": "url", - "named": false - }, - { - "type": "w", - "named": false - }, - { - "type": "watch", - "named": false - }, - { - "type": "watched", - "named": false + "fields": {} }, { - "type": "wd", + "type": "hello", "named": false } -] +]
\ No newline at end of file diff --git a/tree-sitter-yts/src/node-types.json.license b/tree-sitter-yts/src/node-types.json.license deleted file mode 100644 index d4d410f..0000000 --- a/tree-sitter-yts/src/node-types.json.license +++ /dev/null @@ -1,9 +0,0 @@ -yt - A fully featured command line YouTube client - -Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of Yt. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/tree-sitter-yts/src/parser.c b/tree-sitter-yts/src/parser.c index 9552850..95f9999 100644 --- a/tree-sitter-yts/src/parser.c +++ b/tree-sitter-yts/src/parser.c @@ -1,14 +1,4 @@ -/* - * yt - A fully featured command line YouTube client - * - * Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> - * SPDX-License-Identifier: GPL-3.0-or-later - * - * This file is part of Yt. - * - * You should have received a copy of the License along with this program. - * If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - */ +/* Automatically @generated by tree-sitter */ #include "tree_sitter/parser.h" @@ -16,168 +6,34 @@ #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif -#define LANGUAGE_VERSION 14 -#define STATE_COUNT 39 +#define LANGUAGE_VERSION 15 +#define STATE_COUNT 4 #define LARGE_STATE_COUNT 2 -#define SYMBOL_COUNT 48 +#define SYMBOL_COUNT 3 #define ALIAS_COUNT 0 -#define TOKEN_COUNT 36 +#define TOKEN_COUNT 2 #define EXTERNAL_TOKEN_COUNT 0 #define FIELD_COUNT 0 -#define MAX_ALIAS_SEQUENCE_LENGTH 9 +#define MAX_ALIAS_SEQUENCE_LENGTH 1 +#define MAX_RESERVED_WORD_SET_SIZE 0 #define PRODUCTION_ID_COUNT 1 +#define SUPERTYPE_COUNT 0 -enum ts_symbol_identifiers -{ - anon_sym_LF = 1, - anon_sym_pick = 2, - anon_sym_p = 3, - anon_sym_watch = 4, - anon_sym_w = 5, - anon_sym_watched = 6, - anon_sym_wd = 7, - anon_sym_add = 8, - anon_sym_a = 9, - anon_sym_drop = 10, - anon_sym_d = 11, - anon_sym_url = 12, - anon_sym_u = 13, - aux_sym_flag_token1 = 14, - aux_sym_flag_token2 = 15, - aux_sym_flag_token3 = 16, - aux_sym_flag_token4 = 17, - aux_sym_flag_token5 = 18, - aux_sym_flag_token6 = 19, - aux_sym_flag_token7 = 20, - aux_sym_flag_token8 = 21, - aux_sym_flag_token9 = 22, - aux_sym_flag_token10 = 23, - aux_sym_flag_token11 = 24, - aux_sym_flag_token12 = 25, - sym_id = 26, - aux_sym_title_token1 = 27, - anon_sym_LBRACKNoreleasedate_RBRACK = 28, - aux_sym_date_token1 = 29, - anon_sym_LBRACKNoauthor_RBRACK = 30, - anon_sym_LBRACKNoduration_RBRACK = 31, - aux_sym_duration_token1 = 32, - aux_sym_duration_token2 = 33, - sym_comment = 34, - sym_quote = 35, - sym_source_file = 36, - sym_line = 37, - sym_command = 38, - sym_flag = 39, - sym_title = 40, - sym_date = 41, - sym_author = 42, - sym_duration = 43, - sym_url = 44, - sym__q = 45, - aux_sym_source_file_repeat1 = 46, - aux_sym_line_repeat1 = 47, +enum ts_symbol_identifiers { + anon_sym_hello = 1, + sym_source_file = 2, }; -static const char *const ts_symbol_names[] = { +static const char * const ts_symbol_names[] = { [ts_builtin_sym_end] = "end", - [anon_sym_LF] = "\n", - [anon_sym_pick] = "pick", - [anon_sym_p] = "p", - [anon_sym_watch] = "watch", - [anon_sym_w] = "w", - [anon_sym_watched] = "watched", - [anon_sym_wd] = "wd", - [anon_sym_add] = "add", - [anon_sym_a] = "a", - [anon_sym_drop] = "drop", - [anon_sym_d] = "d", - [anon_sym_url] = "url", - [anon_sym_u] = "u", - [aux_sym_flag_token1] = "flag_token1", - [aux_sym_flag_token2] = "flag_token2", - [aux_sym_flag_token3] = "flag_token3", - [aux_sym_flag_token4] = "flag_token4", - [aux_sym_flag_token5] = "flag_token5", - [aux_sym_flag_token6] = "flag_token6", - [aux_sym_flag_token7] = "flag_token7", - [aux_sym_flag_token8] = "flag_token8", - [aux_sym_flag_token9] = "flag_token9", - [aux_sym_flag_token10] = "flag_token10", - [aux_sym_flag_token11] = "flag_token11", - [aux_sym_flag_token12] = "flag_token12", - [sym_id] = "id", - [aux_sym_title_token1] = "title_token1", - [anon_sym_LBRACKNoreleasedate_RBRACK] = "[No release date]", - [aux_sym_date_token1] = "date_token1", - [anon_sym_LBRACKNoauthor_RBRACK] = "[No author]", - [anon_sym_LBRACKNoduration_RBRACK] = "[No duration]", - [aux_sym_duration_token1] = "duration_token1", - [aux_sym_duration_token2] = "duration_token2", - [sym_comment] = "comment", - [sym_quote] = "quote", + [anon_sym_hello] = "hello", [sym_source_file] = "source_file", - [sym_line] = "line", - [sym_command] = "command", - [sym_flag] = "flag", - [sym_title] = "title", - [sym_date] = "date", - [sym_author] = "author", - [sym_duration] = "duration", - [sym_url] = "url", - [sym__q] = "_q", - [aux_sym_source_file_repeat1] = "source_file_repeat1", - [aux_sym_line_repeat1] = "line_repeat1", }; static const TSSymbol ts_symbol_map[] = { [ts_builtin_sym_end] = ts_builtin_sym_end, - [anon_sym_LF] = anon_sym_LF, - [anon_sym_pick] = anon_sym_pick, - [anon_sym_p] = anon_sym_p, - [anon_sym_watch] = anon_sym_watch, - [anon_sym_w] = anon_sym_w, - [anon_sym_watched] = anon_sym_watched, - [anon_sym_wd] = anon_sym_wd, - [anon_sym_add] = anon_sym_add, - [anon_sym_a] = anon_sym_a, - [anon_sym_drop] = anon_sym_drop, - [anon_sym_d] = anon_sym_d, - [anon_sym_url] = anon_sym_url, - [anon_sym_u] = anon_sym_u, - [aux_sym_flag_token1] = aux_sym_flag_token1, - [aux_sym_flag_token2] = aux_sym_flag_token2, - [aux_sym_flag_token3] = aux_sym_flag_token3, - [aux_sym_flag_token4] = aux_sym_flag_token4, - [aux_sym_flag_token5] = aux_sym_flag_token5, - [aux_sym_flag_token6] = aux_sym_flag_token6, - [aux_sym_flag_token7] = aux_sym_flag_token7, - [aux_sym_flag_token8] = aux_sym_flag_token8, - [aux_sym_flag_token9] = aux_sym_flag_token9, - [aux_sym_flag_token10] = aux_sym_flag_token10, - [aux_sym_flag_token11] = aux_sym_flag_token11, - [aux_sym_flag_token12] = aux_sym_flag_token12, - [sym_id] = sym_id, - [aux_sym_title_token1] = aux_sym_title_token1, - [anon_sym_LBRACKNoreleasedate_RBRACK] = anon_sym_LBRACKNoreleasedate_RBRACK, - [aux_sym_date_token1] = aux_sym_date_token1, - [anon_sym_LBRACKNoauthor_RBRACK] = anon_sym_LBRACKNoauthor_RBRACK, - [anon_sym_LBRACKNoduration_RBRACK] = anon_sym_LBRACKNoduration_RBRACK, - [aux_sym_duration_token1] = aux_sym_duration_token1, - [aux_sym_duration_token2] = aux_sym_duration_token2, - [sym_comment] = sym_comment, - [sym_quote] = sym_quote, + [anon_sym_hello] = anon_sym_hello, [sym_source_file] = sym_source_file, - [sym_line] = sym_line, - [sym_command] = sym_command, - [sym_flag] = sym_flag, - [sym_title] = sym_title, - [sym_date] = sym_date, - [sym_author] = sym_author, - [sym_duration] = sym_duration, - [sym_url] = sym_url, - [sym__q] = sym__q, - [aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1, - [aux_sym_line_repeat1] = aux_sym_line_repeat1, }; static const TSSymbolMetadata ts_symbol_metadata[] = { @@ -185,1580 +41,150 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = false, .named = true, }, - [anon_sym_LF] = { + [anon_sym_hello] = { .visible = true, .named = false, }, - [anon_sym_pick] = { - .visible = true, - .named = false, - }, - [anon_sym_p] = { - .visible = true, - .named = false, - }, - [anon_sym_watch] = { - .visible = true, - .named = false, - }, - [anon_sym_w] = { - .visible = true, - .named = false, - }, - [anon_sym_watched] = { - .visible = true, - .named = false, - }, - [anon_sym_wd] = { - .visible = true, - .named = false, - }, - [anon_sym_add] = { - .visible = true, - .named = false, - }, - [anon_sym_a] = { - .visible = true, - .named = false, - }, - [anon_sym_drop] = { - .visible = true, - .named = false, - }, - [anon_sym_d] = { - .visible = true, - .named = false, - }, - [anon_sym_url] = { - .visible = true, - .named = false, - }, - [anon_sym_u] = { - .visible = true, - .named = false, - }, - [aux_sym_flag_token1] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token2] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token3] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token4] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token5] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token6] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token7] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token8] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token9] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token10] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token11] = { - .visible = false, - .named = false, - }, - [aux_sym_flag_token12] = { - .visible = false, - .named = false, - }, - [sym_id] = { - .visible = true, - .named = true, - }, - [aux_sym_title_token1] = { - .visible = false, - .named = false, - }, - [anon_sym_LBRACKNoreleasedate_RBRACK] = { - .visible = true, - .named = false, - }, - [aux_sym_date_token1] = { - .visible = false, - .named = false, - }, - [anon_sym_LBRACKNoauthor_RBRACK] = { - .visible = true, - .named = false, - }, - [anon_sym_LBRACKNoduration_RBRACK] = { - .visible = true, - .named = false, - }, - [aux_sym_duration_token1] = { - .visible = false, - .named = false, - }, - [aux_sym_duration_token2] = { - .visible = false, - .named = false, - }, - [sym_comment] = { - .visible = true, - .named = true, - }, - [sym_quote] = { - .visible = true, - .named = true, - }, [sym_source_file] = { .visible = true, .named = true, }, - [sym_line] = { - .visible = true, - .named = true, - }, - [sym_command] = { - .visible = true, - .named = true, - }, - [sym_flag] = { - .visible = true, - .named = true, - }, - [sym_title] = { - .visible = true, - .named = true, - }, - [sym_date] = { - .visible = true, - .named = true, - }, - [sym_author] = { - .visible = true, - .named = true, - }, - [sym_duration] = { - .visible = true, - .named = true, - }, - [sym_url] = { - .visible = true, - .named = true, - }, - [sym__q] = { - .visible = false, - .named = true, - }, - [aux_sym_source_file_repeat1] = { - .visible = false, - .named = false, - }, - [aux_sym_line_repeat1] = { - .visible = false, - .named = false, - }, }; -static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT] - [MAX_ALIAS_SEQUENCE_LENGTH] - = { - [0] = { 0 }, - }; +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, + [0] = 0, + [1] = 1, + [2] = 2, + [3] = 3, }; -static bool -ts_lex (TSLexer *lexer, TSStateId state) -{ - START_LEXER (); - eof = lexer->eof (lexer); - switch (state) - { +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { case 0: - if (eof) - ADVANCE (78); - ADVANCE_MAP ('"', 134, '#', 133, '-', 21, '[', 24, 'a', 87, 'd', 89, 'p', - 81, 'u', 91, 'w', 83, ); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - SKIP (0); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (44); - END_STATE (); + if (eof) ADVANCE(5); + if (lookahead == 'h') ADVANCE(1); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(0); + END_STATE(); case 1: - if (lookahead == '\n') - ADVANCE (79); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - SKIP (1); - END_STATE (); + if (lookahead == 'e') ADVANCE(3); + END_STATE(); case 2: - if (lookahead == ' ') - ADVANCE (8); - if (lookahead == '=') - ADVANCE (9); - END_STATE (); + if (lookahead == 'l') ADVANCE(4); + END_STATE(); case 3: - if (lookahead == ' ') - ADVANCE (70); - END_STATE (); + if (lookahead == 'l') ADVANCE(2); + END_STATE(); case 4: - if (lookahead == ' ') - ADVANCE (29); - END_STATE (); + if (lookahead == 'o') ADVANCE(6); + END_STATE(); case 5: - if (lookahead == ' ') - ADVANCE (71); - END_STATE (); + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); case 6: - if (lookahead == ' ') - ADVANCE (37); - END_STATE (); - case 7: - if (lookahead == ' ') - ADVANCE (10); - if (lookahead == '=') - ADVANCE (11); - if (lookahead == '-' || ('0' <= lookahead && lookahead <= '9') - || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' - || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE (7); - END_STATE (); - case 8: - if (lookahead == '"') - ADVANCE (92); - if (lookahead == '\'') - ADVANCE (93); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (94); - END_STATE (); - case 9: - if (lookahead == '"') - ADVANCE (97); - if (lookahead == '\'') - ADVANCE (98); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (99); - END_STATE (); - case 10: - if (lookahead == '"') - ADVANCE (102); - if (lookahead == '\'') - ADVANCE (103); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (104); - END_STATE (); - case 11: - if (lookahead == '"') - ADVANCE (107); - if (lookahead == '\'') - ADVANCE (108); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (109); - END_STATE (); - case 12: - if (lookahead == '"') - ADVANCE (96); - if (lookahead != 0) - ADVANCE (12); - END_STATE (); - case 13: - if (lookahead == '"') - ADVANCE (101); - if (lookahead != 0) - ADVANCE (13); - END_STATE (); - case 14: - if (lookahead == '"') - ADVANCE (106); - if (lookahead != 0) - ADVANCE (14); - END_STATE (); - case 15: - if (lookahead == '"') - ADVANCE (111); - if (lookahead != 0) - ADVANCE (15); - END_STATE (); - case 16: - if (lookahead == '\'') - ADVANCE (95); - if (lookahead != 0) - ADVANCE (16); - END_STATE (); - case 17: - if (lookahead == '\'') - ADVANCE (100); - if (lookahead != 0) - ADVANCE (17); - END_STATE (); - case 18: - if (lookahead == '\'') - ADVANCE (105); - if (lookahead != 0) - ADVANCE (18); - END_STATE (); - case 19: - if (lookahead == '\'') - ADVANCE (110); - if (lookahead != 0) - ADVANCE (19); - END_STATE (); - case 20: - if (lookahead == '-') - ADVANCE (21); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - SKIP (20); - if (('0' <= lookahead && lookahead <= '9') - || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE (112); - END_STATE (); - case 21: - if (lookahead == '-') - ADVANCE (76); - if (('0' <= lookahead && lookahead <= '9') - || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' - || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE (2); - END_STATE (); - case 22: - if (lookahead == '-') - ADVANCE (74); - if (lookahead == 'h') - ADVANCE (3); - if (lookahead == 'm') - ADVANCE (5); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (45); - END_STATE (); - case 23: - if (lookahead == '-') - ADVANCE (75); - END_STATE (); - case 24: - if (lookahead == 'N') - ADVANCE (56); - END_STATE (); - case 25: - if (lookahead == '[') - ADVANCE (114); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (115); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 26: - if (lookahead == ']') - ADVANCE (128); - END_STATE (); - case 27: - if (lookahead == ']') - ADVANCE (130); - END_STATE (); - case 28: - if (lookahead == ']') - ADVANCE (126); - END_STATE (); - case 29: - if (lookahead == 'a') - ADVANCE (68); - if (lookahead == 'd') - ADVANCE (67); - if (lookahead == 'r') - ADVANCE (38); - END_STATE (); - case 30: - if (lookahead == 'a') - ADVANCE (62); - END_STATE (); - case 31: - if (lookahead == 'a') - ADVANCE (63); - END_STATE (); - case 32: - if (lookahead == 'a') - ADVANCE (66); - END_STATE (); - case 33: - if (lookahead == 'c') - ADVANCE (49); - END_STATE (); - case 34: - if (lookahead == 'c') - ADVANCE (46); - END_STATE (); - case 35: - if (lookahead == 'd') - ADVANCE (86); - END_STATE (); - case 36: - if (lookahead == 'd') - ADVANCE (84); - END_STATE (); - case 37: - if (lookahead == 'd') - ADVANCE (32); - END_STATE (); - case 38: - if (lookahead == 'e') - ADVANCE (51); - END_STATE (); - case 39: - if (lookahead == 'e') - ADVANCE (30); - END_STATE (); - case 40: - if (lookahead == 'e') - ADVANCE (6); - END_STATE (); - case 41: - if (lookahead == 'e') - ADVANCE (28); - END_STATE (); - case 42: - if (lookahead == 'h') - ADVANCE (3); - if (lookahead == 'm') - ADVANCE (5); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (22); - END_STATE (); - case 43: - if (lookahead == 'h') - ADVANCE (3); - if (lookahead == 'm') - ADVANCE (5); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (42); - END_STATE (); - case 44: - if (lookahead == 'h') - ADVANCE (3); - if (lookahead == 'm') - ADVANCE (5); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (43); - END_STATE (); - case 45: - if (lookahead == 'h') - ADVANCE (3); - if (lookahead == 'm') - ADVANCE (5); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (45); - END_STATE (); - case 46: - if (lookahead == 'h') - ADVANCE (82); - END_STATE (); - case 47: - if (lookahead == 'h') - ADVANCE (57); - END_STATE (); - case 48: - if (lookahead == 'i') - ADVANCE (55); - END_STATE (); - case 49: - if (lookahead == 'k') - ADVANCE (80); - END_STATE (); - case 50: - if (lookahead == 'l') - ADVANCE (90); - END_STATE (); - case 51: - if (lookahead == 'l') - ADVANCE (39); - END_STATE (); - case 52: - if (lookahead == 'm') - ADVANCE (132); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (52); - END_STATE (); - case 53: - if (lookahead == 'n') - ADVANCE (27); - END_STATE (); - case 54: - if (lookahead == 'o') - ADVANCE (58); - END_STATE (); - case 55: - if (lookahead == 'o') - ADVANCE (53); - END_STATE (); - case 56: - if (lookahead == 'o') - ADVANCE (4); - END_STATE (); - case 57: - if (lookahead == 'o') - ADVANCE (60); - END_STATE (); - case 58: - if (lookahead == 'p') - ADVANCE (88); - END_STATE (); - case 59: - if (lookahead == 'r') - ADVANCE (31); - END_STATE (); - case 60: - if (lookahead == 'r') - ADVANCE (26); - END_STATE (); - case 61: - if (lookahead == 's') - ADVANCE (131); - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (61); - END_STATE (); - case 62: - if (lookahead == 's') - ADVANCE (40); - END_STATE (); - case 63: - if (lookahead == 't') - ADVANCE (48); - END_STATE (); - case 64: - if (lookahead == 't') - ADVANCE (34); - END_STATE (); - case 65: - if (lookahead == 't') - ADVANCE (47); - END_STATE (); - case 66: - if (lookahead == 't') - ADVANCE (41); - END_STATE (); - case 67: - if (lookahead == 'u') - ADVANCE (59); - END_STATE (); - case 68: - if (lookahead == 'u') - ADVANCE (65); - END_STATE (); - case 69: - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (124); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 70: - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (52); - END_STATE (); - case 71: - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (61); - END_STATE (); - case 72: - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (23); - END_STATE (); - case 73: - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (127); - END_STATE (); - case 74: - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (72); - END_STATE (); - case 75: - if (('0' <= lookahead && lookahead <= '9')) - ADVANCE (73); - END_STATE (); - case 76: - if (('0' <= lookahead && lookahead <= '9') - || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' - || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE (77); - END_STATE (); - case 77: - if (lookahead == '-' || ('0' <= lookahead && lookahead <= '9') - || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' - || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE (7); - END_STATE (); - case 78: - ACCEPT_TOKEN (ts_builtin_sym_end); - END_STATE (); - case 79: - ACCEPT_TOKEN (anon_sym_LF); - if (lookahead == '\n') - ADVANCE (79); - END_STATE (); - case 80: - ACCEPT_TOKEN (anon_sym_pick); - END_STATE (); - case 81: - ACCEPT_TOKEN (anon_sym_p); - if (lookahead == 'i') - ADVANCE (33); - END_STATE (); - case 82: - ACCEPT_TOKEN (anon_sym_watch); - if (lookahead == 'e') - ADVANCE (36); - END_STATE (); - case 83: - ACCEPT_TOKEN (anon_sym_w); - if (lookahead == 'a') - ADVANCE (64); - if (lookahead == 'd') - ADVANCE (85); - END_STATE (); - case 84: - ACCEPT_TOKEN (anon_sym_watched); - END_STATE (); - case 85: - ACCEPT_TOKEN (anon_sym_wd); - END_STATE (); - case 86: - ACCEPT_TOKEN (anon_sym_add); - END_STATE (); - case 87: - ACCEPT_TOKEN (anon_sym_a); - if (lookahead == 'd') - ADVANCE (35); - END_STATE (); - case 88: - ACCEPT_TOKEN (anon_sym_drop); - END_STATE (); - case 89: - ACCEPT_TOKEN (anon_sym_d); - if (lookahead == 'r') - ADVANCE (54); - END_STATE (); - case 90: - ACCEPT_TOKEN (anon_sym_url); - END_STATE (); - case 91: - ACCEPT_TOKEN (anon_sym_u); - if (lookahead == 'r') - ADVANCE (50); - END_STATE (); - case 92: - ACCEPT_TOKEN (aux_sym_flag_token1); - if (lookahead == '"') - ADVANCE (94); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (12); - if (lookahead != 0) - ADVANCE (92); - END_STATE (); - case 93: - ACCEPT_TOKEN (aux_sym_flag_token1); - if (lookahead == '\'') - ADVANCE (94); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (16); - if (lookahead != 0) - ADVANCE (93); - END_STATE (); - case 94: - ACCEPT_TOKEN (aux_sym_flag_token1); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (94); - END_STATE (); - case 95: - ACCEPT_TOKEN (aux_sym_flag_token2); - END_STATE (); - case 96: - ACCEPT_TOKEN (aux_sym_flag_token3); - END_STATE (); - case 97: - ACCEPT_TOKEN (aux_sym_flag_token4); - if (lookahead == '"') - ADVANCE (99); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (13); - if (lookahead != 0) - ADVANCE (97); - END_STATE (); - case 98: - ACCEPT_TOKEN (aux_sym_flag_token4); - if (lookahead == '\'') - ADVANCE (99); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (17); - if (lookahead != 0) - ADVANCE (98); - END_STATE (); - case 99: - ACCEPT_TOKEN (aux_sym_flag_token4); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (99); - END_STATE (); - case 100: - ACCEPT_TOKEN (aux_sym_flag_token5); - END_STATE (); - case 101: - ACCEPT_TOKEN (aux_sym_flag_token6); - END_STATE (); - case 102: - ACCEPT_TOKEN (aux_sym_flag_token7); - if (lookahead == '"') - ADVANCE (104); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (14); - if (lookahead != 0) - ADVANCE (102); - END_STATE (); - case 103: - ACCEPT_TOKEN (aux_sym_flag_token7); - if (lookahead == '\'') - ADVANCE (104); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (18); - if (lookahead != 0) - ADVANCE (103); - END_STATE (); - case 104: - ACCEPT_TOKEN (aux_sym_flag_token7); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (104); - END_STATE (); - case 105: - ACCEPT_TOKEN (aux_sym_flag_token8); - END_STATE (); - case 106: - ACCEPT_TOKEN (aux_sym_flag_token9); - END_STATE (); - case 107: - ACCEPT_TOKEN (aux_sym_flag_token10); - if (lookahead == '"') - ADVANCE (109); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (15); - if (lookahead != 0) - ADVANCE (107); - END_STATE (); - case 108: - ACCEPT_TOKEN (aux_sym_flag_token10); - if (lookahead == '\'') - ADVANCE (109); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (19); - if (lookahead != 0) - ADVANCE (108); - END_STATE (); - case 109: - ACCEPT_TOKEN (aux_sym_flag_token10); - if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) - && lookahead != ' ') - ADVANCE (109); - END_STATE (); - case 110: - ACCEPT_TOKEN (aux_sym_flag_token11); - END_STATE (); - case 111: - ACCEPT_TOKEN (aux_sym_flag_token12); - END_STATE (); - case 112: - ACCEPT_TOKEN (sym_id); - if (('0' <= lookahead && lookahead <= '9') - || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE (112); - END_STATE (); - case 113: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == ' ') - ADVANCE (117); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 114: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'N') - ADVANCE (119); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 115: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == '[') - ADVANCE (114); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (115); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 116: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == ']') - ADVANCE (129); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 117: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'a') - ADVANCE (123); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 118: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'h') - ADVANCE (120); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 119: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'o') - ADVANCE (113); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 120: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'o') - ADVANCE (121); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 121: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'r') - ADVANCE (116); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 122: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 't') - ADVANCE (118); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 123: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead == 'u') - ADVANCE (122); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 124: - ACCEPT_TOKEN (aux_sym_title_token1); - if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') - ADVANCE (124); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 125: - ACCEPT_TOKEN (aux_sym_title_token1); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 126: - ACCEPT_TOKEN (anon_sym_LBRACKNoreleasedate_RBRACK); - END_STATE (); - case 127: - ACCEPT_TOKEN (aux_sym_date_token1); - END_STATE (); - case 128: - ACCEPT_TOKEN (anon_sym_LBRACKNoauthor_RBRACK); - END_STATE (); - case 129: - ACCEPT_TOKEN (anon_sym_LBRACKNoauthor_RBRACK); - if (lookahead != 0 && lookahead != '"') - ADVANCE (125); - END_STATE (); - case 130: - ACCEPT_TOKEN (anon_sym_LBRACKNoduration_RBRACK); - END_STATE (); - case 131: - ACCEPT_TOKEN (aux_sym_duration_token1); - END_STATE (); - case 132: - ACCEPT_TOKEN (aux_sym_duration_token2); - END_STATE (); - case 133: - ACCEPT_TOKEN (sym_comment); - if (lookahead != 0 && lookahead != '\n') - ADVANCE (133); - END_STATE (); - case 134: - ACCEPT_TOKEN (sym_quote); - END_STATE (); + ACCEPT_TOKEN(anon_sym_hello); + END_STATE(); default: return false; - } + } } -static const TSLexMode ts_lex_modes[STATE_COUNT] = { - [0] = { .lex_state = 0 }, [1] = { .lex_state = 0 }, - [2] = { .lex_state = 0 }, [3] = { .lex_state = 0 }, - [4] = { .lex_state = 20 }, [5] = { .lex_state = 20 }, - [6] = { .lex_state = 20 }, [7] = { .lex_state = 0 }, - [8] = { .lex_state = 0 }, [9] = { .lex_state = 20 }, - [10] = { .lex_state = 20 }, [11] = { .lex_state = 0 }, - [12] = { .lex_state = 0 }, [13] = { .lex_state = 0 }, - [14] = { .lex_state = 0 }, [15] = { .lex_state = 0 }, - [16] = { .lex_state = 0 }, [17] = { .lex_state = 0 }, - [18] = { .lex_state = 0 }, [19] = { .lex_state = 0 }, - [20] = { .lex_state = 0 }, [21] = { .lex_state = 0 }, - [22] = { .lex_state = 0 }, [23] = { .lex_state = 25 }, - [24] = { .lex_state = 0 }, [25] = { .lex_state = 0 }, - [26] = { .lex_state = 0 }, [27] = { .lex_state = 0 }, - [28] = { .lex_state = 0 }, [29] = { .lex_state = 69 }, - [30] = { .lex_state = 0 }, [31] = { .lex_state = 0 }, - [32] = { .lex_state = 0 }, [33] = { .lex_state = 0 }, - [34] = { .lex_state = 1 }, [35] = { .lex_state = 0 }, - [36] = { .lex_state = 1 }, [37] = { .lex_state = 1 }, - [38] = { .lex_state = 69 }, +static const TSLexerMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 0}, + [2] = {.lex_state = 0}, + [3] = {.lex_state = 0}, }; static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { - [0] = { + [STATE(0)] = { [ts_builtin_sym_end] = ACTIONS(1), - [anon_sym_pick] = ACTIONS(1), - [anon_sym_p] = ACTIONS(1), - [anon_sym_watch] = ACTIONS(1), - [anon_sym_w] = ACTIONS(1), - [anon_sym_watched] = ACTIONS(1), - [anon_sym_wd] = ACTIONS(1), - [anon_sym_add] = ACTIONS(1), - [anon_sym_a] = ACTIONS(1), - [anon_sym_drop] = ACTIONS(1), - [anon_sym_d] = ACTIONS(1), - [anon_sym_url] = ACTIONS(1), - [anon_sym_u] = ACTIONS(1), - [aux_sym_flag_token1] = ACTIONS(1), - [aux_sym_flag_token2] = ACTIONS(1), - [aux_sym_flag_token3] = ACTIONS(1), - [aux_sym_flag_token4] = ACTIONS(1), - [aux_sym_flag_token5] = ACTIONS(1), - [aux_sym_flag_token6] = ACTIONS(1), - [aux_sym_flag_token7] = ACTIONS(1), - [aux_sym_flag_token8] = ACTIONS(1), - [aux_sym_flag_token9] = ACTIONS(1), - [aux_sym_flag_token10] = ACTIONS(1), - [aux_sym_flag_token11] = ACTIONS(1), - [aux_sym_flag_token12] = ACTIONS(1), - [anon_sym_LBRACKNoreleasedate_RBRACK] = ACTIONS(1), - [aux_sym_date_token1] = ACTIONS(1), - [anon_sym_LBRACKNoauthor_RBRACK] = ACTIONS(1), - [anon_sym_LBRACKNoduration_RBRACK] = ACTIONS(1), - [aux_sym_duration_token1] = ACTIONS(1), - [aux_sym_duration_token2] = ACTIONS(1), - [sym_comment] = ACTIONS(1), - [sym_quote] = ACTIONS(1), + [anon_sym_hello] = ACTIONS(1), }, - [1] = { - [sym_source_file] = STATE(30), - [sym_line] = STATE(3), - [sym_command] = STATE(4), - [aux_sym_source_file_repeat1] = STATE(3), - [ts_builtin_sym_end] = ACTIONS(3), - [anon_sym_pick] = ACTIONS(5), - [anon_sym_p] = ACTIONS(7), - [anon_sym_watch] = ACTIONS(7), - [anon_sym_w] = ACTIONS(7), - [anon_sym_watched] = ACTIONS(5), - [anon_sym_wd] = ACTIONS(5), - [anon_sym_add] = ACTIONS(5), - [anon_sym_a] = ACTIONS(7), - [anon_sym_drop] = ACTIONS(5), - [anon_sym_d] = ACTIONS(7), - [anon_sym_url] = ACTIONS(5), - [anon_sym_u] = ACTIONS(7), - [sym_comment] = ACTIONS(9), + [STATE(1)] = { + [sym_source_file] = STATE(3), + [anon_sym_hello] = ACTIONS(3), }, }; static const uint16_t ts_small_parse_table[] = { - [0] = 6, - ACTIONS (11), - 1, - ts_builtin_sym_end, - ACTIONS (19), - 1, - sym_comment, - STATE (4), - 1, - sym_command, - STATE (2), - 2, - sym_line, - aux_sym_source_file_repeat1, - ACTIONS (13), - 6, - anon_sym_pick, - anon_sym_watched, - anon_sym_wd, - anon_sym_add, - anon_sym_drop, - anon_sym_url, - ACTIONS (16), - 6, - anon_sym_p, - anon_sym_watch, - anon_sym_w, - anon_sym_a, - anon_sym_d, - anon_sym_u, - [30] = 6, - ACTIONS (22), - 1, - ts_builtin_sym_end, - ACTIONS (24), - 1, - sym_comment, - STATE (4), - 1, - sym_command, - STATE (2), - 2, - sym_line, - aux_sym_source_file_repeat1, - ACTIONS (5), - 6, - anon_sym_pick, - anon_sym_watched, - anon_sym_wd, - anon_sym_add, - anon_sym_drop, - anon_sym_url, - ACTIONS (7), - 6, - anon_sym_p, - anon_sym_watch, - anon_sym_w, - anon_sym_a, - anon_sym_d, - anon_sym_u, - [60] = 3, - ACTIONS (28), - 1, - sym_id, - STATE (5), - 2, - sym_flag, - aux_sym_line_repeat1, - ACTIONS (26), - 12, - aux_sym_flag_token1, - aux_sym_flag_token2, - aux_sym_flag_token3, - aux_sym_flag_token4, - aux_sym_flag_token5, - aux_sym_flag_token6, - aux_sym_flag_token7, - aux_sym_flag_token8, - aux_sym_flag_token9, - aux_sym_flag_token10, - aux_sym_flag_token11, - aux_sym_flag_token12, - [82] = 3, - ACTIONS (30), - 1, - sym_id, - STATE (6), - 2, - sym_flag, - aux_sym_line_repeat1, - ACTIONS (26), - 12, - aux_sym_flag_token1, - aux_sym_flag_token2, - aux_sym_flag_token3, - aux_sym_flag_token4, - aux_sym_flag_token5, - aux_sym_flag_token6, - aux_sym_flag_token7, - aux_sym_flag_token8, - aux_sym_flag_token9, - aux_sym_flag_token10, - aux_sym_flag_token11, - aux_sym_flag_token12, - [104] = 3, - ACTIONS (35), - 1, - sym_id, - STATE (6), - 2, - sym_flag, - aux_sym_line_repeat1, - ACTIONS (32), - 12, - aux_sym_flag_token1, - aux_sym_flag_token2, - aux_sym_flag_token3, - aux_sym_flag_token4, - aux_sym_flag_token5, - aux_sym_flag_token6, - aux_sym_flag_token7, - aux_sym_flag_token8, - aux_sym_flag_token9, - aux_sym_flag_token10, - aux_sym_flag_token11, - aux_sym_flag_token12, - [126] = 2, - ACTIONS (39), - 6, - anon_sym_p, - anon_sym_watch, - anon_sym_w, - anon_sym_a, - anon_sym_d, - anon_sym_u, - ACTIONS (37), - 8, - ts_builtin_sym_end, - anon_sym_pick, - anon_sym_watched, - anon_sym_wd, - anon_sym_add, - anon_sym_drop, - anon_sym_url, - sym_comment, - [145] = 2, - ACTIONS (43), - 6, - anon_sym_p, - anon_sym_watch, - anon_sym_w, - anon_sym_a, - anon_sym_d, - anon_sym_u, - ACTIONS (41), - 8, - ts_builtin_sym_end, - anon_sym_pick, - anon_sym_watched, - anon_sym_wd, - anon_sym_add, - anon_sym_drop, - anon_sym_url, - sym_comment, - [164] = 2, - ACTIONS (47), - 1, - sym_id, - ACTIONS (45), - 12, - aux_sym_flag_token1, - aux_sym_flag_token2, - aux_sym_flag_token3, - aux_sym_flag_token4, - aux_sym_flag_token5, - aux_sym_flag_token6, - aux_sym_flag_token7, - aux_sym_flag_token8, - aux_sym_flag_token9, - aux_sym_flag_token10, - aux_sym_flag_token11, - aux_sym_flag_token12, - [182] = 2, - ACTIONS (51), - 1, - sym_id, - ACTIONS (49), - 12, - aux_sym_flag_token1, - aux_sym_flag_token2, - aux_sym_flag_token3, - aux_sym_flag_token4, - aux_sym_flag_token5, - aux_sym_flag_token6, - aux_sym_flag_token7, - aux_sym_flag_token8, - aux_sym_flag_token9, - aux_sym_flag_token10, - aux_sym_flag_token11, - aux_sym_flag_token12, - [200] = 3, - ACTIONS (53), - 1, - sym_quote, - STATE (12), - 1, - sym_title, - STATE (38), - 1, - sym__q, - [210] = 3, - ACTIONS (55), - 1, - sym_quote, - STATE (14), - 1, - sym_date, - STATE (24), - 1, - sym__q, - [220] = 3, - ACTIONS (53), - 1, - sym_quote, - STATE (15), - 1, - sym_title, - STATE (38), - 1, - sym__q, - [230] = 3, - ACTIONS (57), - 1, - sym_quote, - STATE (16), - 1, - sym_author, - STATE (23), - 1, - sym__q, - [240] = 3, - ACTIONS (55), - 1, - sym_quote, - STATE (17), - 1, - sym_date, - STATE (24), - 1, - sym__q, - [250] = 3, - ACTIONS (59), - 1, - sym_quote, - STATE (18), - 1, - sym_duration, - STATE (19), - 1, - sym__q, - [260] = 3, - ACTIONS (57), - 1, - sym_quote, - STATE (20), - 1, - sym_author, - STATE (23), - 1, - sym__q, - [270] = 3, - ACTIONS (61), - 1, - sym_quote, - STATE (29), - 1, - sym__q, - STATE (34), - 1, - sym_url, - [280] = 1, - ACTIONS (63), - 3, - anon_sym_LBRACKNoduration_RBRACK, - aux_sym_duration_token1, - aux_sym_duration_token2, - [286] = 3, - ACTIONS (59), - 1, - sym_quote, - STATE (19), - 1, - sym__q, - STATE (21), - 1, - sym_duration, - [296] = 3, - ACTIONS (61), - 1, - sym_quote, - STATE (29), - 1, - sym__q, - STATE (36), - 1, - sym_url, - [306] = 2, - ACTIONS (65), - 1, - sym_quote, - STATE (33), - 1, - sym__q, - [313] = 1, - ACTIONS (67), - 2, - aux_sym_title_token1, - anon_sym_LBRACKNoauthor_RBRACK, - [318] = 1, - ACTIONS (69), - 2, - anon_sym_LBRACKNoreleasedate_RBRACK, - aux_sym_date_token1, - [323] = 2, - ACTIONS (71), - 1, - sym_quote, - STATE (31), - 1, - sym__q, - [330] = 2, - ACTIONS (73), - 1, - sym_quote, - STATE (35), - 1, - sym__q, - [337] = 2, - ACTIONS (75), - 1, - sym_quote, - STATE (32), - 1, - sym__q, - [344] = 2, - ACTIONS (77), - 1, - sym_quote, - STATE (37), - 1, - sym__q, - [351] = 1, - ACTIONS (79), - 1, - aux_sym_title_token1, - [355] = 1, - ACTIONS (81), - 1, - ts_builtin_sym_end, - [359] = 1, - ACTIONS (83), - 1, - sym_quote, - [363] = 1, - ACTIONS (85), - 1, - sym_quote, - [367] = 1, - ACTIONS (87), - 1, - sym_quote, - [371] = 1, - ACTIONS (89), - 1, - anon_sym_LF, - [375] = 1, - ACTIONS (91), - 1, - sym_quote, - [379] = 1, - ACTIONS (93), - 1, - anon_sym_LF, - [383] = 1, - ACTIONS (95), - 1, - anon_sym_LF, - [387] = 1, - ACTIONS (97), - 1, - aux_sym_title_token1, + [0] = 1, + ACTIONS(5), 1, + ts_builtin_sym_end, + [4] = 1, + ACTIONS(7), 1, + ts_builtin_sym_end, }; static const uint32_t ts_small_parse_table_map[] = { - [SMALL_STATE (2)] = 0, [SMALL_STATE (3)] = 30, [SMALL_STATE (4)] = 60, - [SMALL_STATE (5)] = 82, [SMALL_STATE (6)] = 104, [SMALL_STATE (7)] = 126, - [SMALL_STATE (8)] = 145, [SMALL_STATE (9)] = 164, [SMALL_STATE (10)] = 182, - [SMALL_STATE (11)] = 200, [SMALL_STATE (12)] = 210, [SMALL_STATE (13)] = 220, - [SMALL_STATE (14)] = 230, [SMALL_STATE (15)] = 240, [SMALL_STATE (16)] = 250, - [SMALL_STATE (17)] = 260, [SMALL_STATE (18)] = 270, [SMALL_STATE (19)] = 280, - [SMALL_STATE (20)] = 286, [SMALL_STATE (21)] = 296, [SMALL_STATE (22)] = 306, - [SMALL_STATE (23)] = 313, [SMALL_STATE (24)] = 318, [SMALL_STATE (25)] = 323, - [SMALL_STATE (26)] = 330, [SMALL_STATE (27)] = 337, [SMALL_STATE (28)] = 344, - [SMALL_STATE (29)] = 351, [SMALL_STATE (30)] = 355, [SMALL_STATE (31)] = 359, - [SMALL_STATE (32)] = 363, [SMALL_STATE (33)] = 367, [SMALL_STATE (34)] = 371, - [SMALL_STATE (35)] = 375, [SMALL_STATE (36)] = 379, [SMALL_STATE (37)] = 383, - [SMALL_STATE (38)] = 387, + [SMALL_STATE(2)] = 0, + [SMALL_STATE(3)] = 4, }; static const TSParseActionEntry ts_parse_actions[] = { - [0] = { .entry = { .count = 0, .reusable = false } }, - [1] = { .entry = { .count = 1, .reusable = false } }, - RECOVER (), - [3] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_source_file, 0, 0, 0), - [5] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (10), - [7] = { .entry = { .count = 1, .reusable = false } }, - SHIFT (10), - [9] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (3), - [11] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (aux_sym_source_file_repeat1, 2, 0, 0), - [13] = { .entry = { .count = 2, .reusable = true } }, - REDUCE (aux_sym_source_file_repeat1, 2, 0, 0), - SHIFT_REPEAT (10), - [16] = { .entry = { .count = 2, .reusable = false } }, - REDUCE (aux_sym_source_file_repeat1, 2, 0, 0), - SHIFT_REPEAT (10), - [19] = { .entry = { .count = 2, .reusable = true } }, - REDUCE (aux_sym_source_file_repeat1, 2, 0, 0), - SHIFT_REPEAT (2), - [22] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_source_file, 1, 0, 0), - [24] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (2), - [26] = { .entry = { .count = 1, .reusable = false } }, - SHIFT (9), - [28] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (11), - [30] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (13), - [32] = { .entry = { .count = 2, .reusable = false } }, - REDUCE (aux_sym_line_repeat1, 2, 0, 0), - SHIFT_REPEAT (9), - [35] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (aux_sym_line_repeat1, 2, 0, 0), - [37] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_line, 8, 0, 0), - [39] = { .entry = { .count = 1, .reusable = false } }, - REDUCE (sym_line, 8, 0, 0), - [41] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_line, 9, 0, 0), - [43] = { .entry = { .count = 1, .reusable = false } }, - REDUCE (sym_line, 9, 0, 0), - [45] = { .entry = { .count = 1, .reusable = false } }, - REDUCE (sym_flag, 1, 0, 0), - [47] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_flag, 1, 0, 0), - [49] = { .entry = { .count = 1, .reusable = false } }, - REDUCE (sym_command, 1, 0, 0), - [51] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_command, 1, 0, 0), - [53] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (38), - [55] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (24), - [57] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (23), - [59] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (19), - [61] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (29), - [63] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (26), - [65] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (33), - [67] = { .entry = { .count = 1, .reusable = false } }, - SHIFT (25), - [69] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (27), - [71] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (31), - [73] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (35), - [75] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (32), - [77] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (37), - [79] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (28), - [81] = { .entry = { .count = 1, .reusable = true } }, - ACCEPT_INPUT (), - [83] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_author, 3, 0, 0), - [85] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_date, 3, 0, 0), - [87] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_title, 3, 0, 0), - [89] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (7), - [91] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_duration, 3, 0, 0), - [93] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (8), - [95] = { .entry = { .count = 1, .reusable = true } }, - REDUCE (sym_url, 3, 0, 0), - [97] = { .entry = { .count = 1, .reusable = true } }, - SHIFT (22), + [0] = {.entry = {.count = 0, .reusable = false}}, + [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), + [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), + [5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0), + [7] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), }; #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #ifdef TREE_SITTER_HIDE_SYMBOLS #define TS_PUBLIC #elif defined(_WIN32) -#define TS_PUBLIC __declspec (dllexport) +#define TS_PUBLIC __declspec(dllexport) #else -#define TS_PUBLIC __attribute__ ((visibility ("default"))) +#define TS_PUBLIC __attribute__((visibility("default"))) #endif - TS_PUBLIC const TSLanguage * - tree_sitter_yts (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, - .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; - } +TS_PUBLIC const TSLanguage *tree_sitter_yts(void) { + static const TSLanguage language = { + .abi_version = LANGUAGE_VERSION, + .symbol_count = SYMBOL_COUNT, + .alias_count = ALIAS_COUNT, + .token_count = TOKEN_COUNT, + .external_token_count = EXTERNAL_TOKEN_COUNT, + .state_count = STATE_COUNT, + .large_state_count = LARGE_STATE_COUNT, + .production_id_count = PRODUCTION_ID_COUNT, + .supertype_count = SUPERTYPE_COUNT, + .field_count = FIELD_COUNT, + .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, + .parse_table = &ts_parse_table[0][0], + .small_parse_table = ts_small_parse_table, + .small_parse_table_map = ts_small_parse_table_map, + .parse_actions = ts_parse_actions, + .symbol_names = ts_symbol_names, + .symbol_metadata = ts_symbol_metadata, + .public_symbol_map = ts_symbol_map, + .alias_map = ts_non_terminal_alias_map, + .alias_sequences = &ts_alias_sequences[0][0], + .lex_modes = (const void*)ts_lex_modes, + .lex_fn = ts_lex, + .primary_state_ids = ts_primary_state_ids, + .name = "yts", + .max_reserved_word_set_size = 0, + .metadata = { + .major_version = 0, + .minor_version = 1, + .patch_version = 0, + }, + }; + return &language; +} #ifdef __cplusplus } #endif diff --git a/tree-sitter-yts/src/tree_sitter/alloc.h b/tree-sitter-yts/src/tree_sitter/alloc.h index fcaeaad..1abdd12 100644 --- a/tree-sitter-yts/src/tree_sitter/alloc.h +++ b/tree-sitter-yts/src/tree_sitter/alloc.h @@ -1,21 +1,8 @@ -/* - * yt - A fully featured command line YouTube client - * - * Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> - * SPDX-License-Identifier: GPL-3.0-or-later - * - * This file is part of Yt. - * - * You should have received a copy of the License along with this program. - * If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - */ - #ifndef TREE_SITTER_ALLOC_H_ #define TREE_SITTER_ALLOC_H_ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include <stdbool.h> @@ -25,37 +12,37 @@ extern "C" // Allow clients to override allocation functions #ifdef TREE_SITTER_REUSE_ALLOCATOR - extern void *(*ts_current_malloc) (size_t size); - extern void *(*ts_current_calloc) (size_t count, size_t size); - extern void *(*ts_current_realloc) (void *ptr, size_t size); - extern void (*ts_current_free) (void *ptr); +extern void *(*ts_current_malloc)(size_t size); +extern void *(*ts_current_calloc)(size_t count, size_t size); +extern void *(*ts_current_realloc)(void *ptr, size_t size); +extern void (*ts_current_free)(void *ptr); #ifndef ts_malloc -#define ts_malloc ts_current_malloc +#define ts_malloc ts_current_malloc #endif #ifndef ts_calloc -#define ts_calloc ts_current_calloc +#define ts_calloc ts_current_calloc #endif #ifndef ts_realloc #define ts_realloc ts_current_realloc #endif #ifndef ts_free -#define ts_free ts_current_free +#define ts_free ts_current_free #endif #else #ifndef ts_malloc -#define ts_malloc malloc +#define ts_malloc malloc #endif #ifndef ts_calloc -#define ts_calloc calloc +#define ts_calloc calloc #endif #ifndef ts_realloc #define ts_realloc realloc #endif #ifndef ts_free -#define ts_free free +#define ts_free free #endif #endif diff --git a/tree-sitter-yts/src/tree_sitter/array.h b/tree-sitter-yts/src/tree_sitter/array.h index 576d72e..56fc8cd 100644 --- a/tree-sitter-yts/src/tree_sitter/array.h +++ b/tree-sitter-yts/src/tree_sitter/array.h @@ -1,21 +1,8 @@ -/* - * yt - A fully featured command line YouTube client - * - * Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> - * SPDX-License-Identifier: GPL-3.0-or-later - * - * This file is part of Yt. - * - * You should have received a copy of the License along with this program. - * If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - */ - #ifndef TREE_SITTER_ARRAY_H_ #define TREE_SITTER_ARRAY_H_ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include "./alloc.h" @@ -27,36 +14,37 @@ extern "C" #include <string.h> #ifdef _MSC_VER +#pragma warning(push) #pragma warning(disable : 4101) #elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" #endif -#define Array(T) \ - struct \ - { \ - T *contents; \ - uint32_t size; \ - uint32_t capacity; \ +#define Array(T) \ + struct { \ + T *contents; \ + uint32_t size; \ + uint32_t capacity; \ } /// Initialize an array. -#define array_init(self) \ +#define array_init(self) \ ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL) /// Create an empty array. -#define array_new() { NULL, 0, 0 } +#define array_new() \ + { NULL, 0, 0 } /// Get a pointer to the element at a given `index` in the array. -#define array_get(self, _index) \ - (assert ((uint32_t)(_index) < (self)->size), &(self)->contents[_index]) +#define array_get(self, _index) \ + (assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index]) /// Get a pointer to the first element in the array. -#define array_front(self) array_get (self, 0) +#define array_front(self) array_get(self, 0) /// Get a pointer to the last element in the array. -#define array_back(self) array_get (self, (self)->size - 1) +#define array_back(self) array_get(self, (self)->size - 1) /// Clear the array, setting its size to zero. Note that this does not free any /// memory allocated for the array's contents. @@ -64,69 +52,96 @@ extern "C" /// Reserve `new_capacity` elements of space in the array. If `new_capacity` is /// less than the array's current capacity, this function has no effect. -#define array_reserve(self, new_capacity) \ - _array__reserve ((Array *)(self), array_elem_size (self), new_capacity) +#define array_reserve(self, new_capacity) \ + ((self)->contents = _array__reserve( \ + (void *)(self)->contents, &(self)->capacity, \ + array_elem_size(self), new_capacity) \ + ) /// Free any memory allocated for this array. Note that this does not free any /// memory allocated for the array's contents. -#define array_delete(self) _array__delete ((Array *)(self)) +#define array_delete(self) \ + do { \ + if ((self)->contents) ts_free((self)->contents); \ + (self)->contents = NULL; \ + (self)->size = 0; \ + (self)->capacity = 0; \ + } while (0) /// Push a new `element` onto the end of the array. -#define array_push(self, element) \ - (_array__grow ((Array *)(self), 1, array_elem_size (self)), \ - (self)->contents[(self)->size++] = (element)) +#define array_push(self, element) \ + do { \ + (self)->contents = _array__grow( \ + (void *)(self)->contents, (self)->size, &(self)->capacity, \ + 1, array_elem_size(self) \ + ); \ + (self)->contents[(self)->size++] = (element); \ + } while(0) /// Increase the array's size by `count` elements. /// New elements are zero-initialized. -#define array_grow_by(self, count) \ - do \ - { \ - if ((count) == 0) \ - break; \ - _array__grow ((Array *)(self), count, array_elem_size (self)); \ - memset ((self)->contents + (self)->size, 0, \ - (count) * array_elem_size (self)); \ - (self)->size += (count); \ - } \ - while (0) +#define array_grow_by(self, count) \ + do { \ + if ((count) == 0) break; \ + (self)->contents = _array__grow( \ + (self)->contents, (self)->size, &(self)->capacity, \ + count, array_elem_size(self) \ + ); \ + memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \ + (self)->size += (count); \ + } while (0) /// Append all elements from one array to the end of another. -#define array_push_all(self, other) \ - array_extend ((self), (other)->size, (other)->contents) +#define array_push_all(self, other) \ + array_extend((self), (other)->size, (other)->contents) -/// Append `count` elements to the end of the array, reading their values from -/// the `contents` pointer. -#define array_extend(self, count, contents) \ - _array__splice ((Array *)(self), array_elem_size (self), (self)->size, 0, \ - count, contents) +/// Append `count` elements to the end of the array, reading their values from the +/// `contents` pointer. +#define array_extend(self, count, other_contents) \ + (self)->contents = _array__splice( \ + (void*)(self)->contents, &(self)->size, &(self)->capacity, \ + array_elem_size(self), (self)->size, 0, count, other_contents \ + ) -/// Remove `old_count` elements from the array starting at the given `index`. -/// At the same index, insert `new_count` new elements, reading their values -/// from the `new_contents` pointer. -#define array_splice(self, _index, old_count, new_count, new_contents) \ - _array__splice ((Array *)(self), array_elem_size (self), _index, old_count, \ - new_count, new_contents) +/// Remove `old_count` elements from the array starting at the given `index`. At +/// the same index, insert `new_count` new elements, reading their values from the +/// `new_contents` pointer. +#define array_splice(self, _index, old_count, new_count, new_contents) \ + (self)->contents = _array__splice( \ + (void *)(self)->contents, &(self)->size, &(self)->capacity, \ + array_elem_size(self), _index, old_count, new_count, new_contents \ + ) /// Insert one `element` into the array at the given `index`. -#define array_insert(self, _index, element) \ - _array__splice ((Array *)(self), array_elem_size (self), _index, 0, 1, \ - &(element)) +#define array_insert(self, _index, element) \ + (self)->contents = _array__splice( \ + (void *)(self)->contents, &(self)->size, &(self)->capacity, \ + array_elem_size(self), _index, 0, 1, &(element) \ + ) /// Remove one element from the array at the given `index`. -#define array_erase(self, _index) \ - _array__erase ((Array *)(self), array_elem_size (self), _index) +#define array_erase(self, _index) \ + _array__erase((void *)(self)->contents, &(self)->size, array_elem_size(self), _index) /// Pop the last element off the array, returning the element by value. #define array_pop(self) ((self)->contents[--(self)->size]) /// Assign the contents of one array to another, reallocating if necessary. -#define array_assign(self, other) \ - _array__assign ((Array *)(self), (const Array *)(other), \ - array_elem_size (self)) +#define array_assign(self, other) \ + (self)->contents = _array__assign( \ + (void *)(self)->contents, &(self)->size, &(self)->capacity, \ + (const void *)(other)->contents, (other)->size, array_elem_size(self) \ + ) /// Swap one array with another -#define array_swap(self, other) \ - _array__swap ((Array *)(self), (Array *)(other)) +#define array_swap(self, other) \ + do { \ + void *_array_swap_tmp = (void *)(self)->contents; \ + (self)->contents = (other)->contents; \ + (other)->contents = _array_swap_tmp; \ + _array__swap(&(self)->size, &(self)->capacity, \ + &(other)->size, &(other)->capacity); \ + } while (0) /// Get the size of the array contents #define array_elem_size(self) (sizeof *(self)->contents) @@ -139,198 +154,171 @@ extern "C" /// out-parameter is set to true. Otherwise, `index` is set to an index where /// `needle` should be inserted in order to preserve the sorting, and `exists` /// is set to false. -#define array_search_sorted_with(self, compare, needle, _index, _exists) \ - _array__search_sorted (self, 0, compare, , needle, _index, _exists) +#define array_search_sorted_with(self, compare, needle, _index, _exists) \ + _array__search_sorted(self, 0, compare, , needle, _index, _exists) /// Search a sorted array for a given `needle` value, using integer comparisons -/// of a given struct field (specified with a leading dot) to determine the -/// order. +/// of a given struct field (specified with a leading dot) to determine the order. /// /// See also `array_search_sorted_with`. -#define array_search_sorted_by(self, field, needle, _index, _exists) \ - _array__search_sorted (self, 0, _compare_int, field, needle, _index, _exists) +#define array_search_sorted_by(self, field, needle, _index, _exists) \ + _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists) /// Insert a given `value` into a sorted array, using the given `compare` /// callback to determine the order. -#define array_insert_sorted_with(self, compare, value) \ - do \ - { \ - unsigned _index, _exists; \ - array_search_sorted_with (self, compare, &(value), &_index, &_exists); \ - if (!_exists) \ - array_insert (self, _index, value); \ - } \ - while (0) +#define array_insert_sorted_with(self, compare, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_with(self, compare, &(value), &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) /// Insert a given `value` into a sorted array, using integer comparisons of /// a given struct field (specified with a leading dot) to determine the order. /// /// See also `array_search_sorted_by`. -#define array_insert_sorted_by(self, field, value) \ - do \ - { \ - unsigned _index, _exists; \ - array_search_sorted_by (self, field, (value)field, &_index, &_exists); \ - if (!_exists) \ - array_insert (self, _index, value); \ - } \ - while (0) - - // Private +#define array_insert_sorted_by(self, field, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_by(self, field, (value) field, &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) - typedef Array (void) Array; +// Private - /// This is not what you're looking for, see `array_delete`. - static inline void - _array__delete (Array *self) - { - if (self->contents) - { - ts_free (self->contents); - self->contents = NULL; - self->size = 0; - self->capacity = 0; - } - } +// Pointers to individual `Array` fields (rather than the entire `Array` itself) +// are passed to the various `_array__*` functions below to address strict aliasing +// violations that arises when the _entire_ `Array` struct is passed as `Array(void)*`. +// +// The `Array` type itself was not altered as a solution in order to avoid breakage +// with existing consumers (in particular, parsers with external scanners). - /// This is not what you're looking for, see `array_erase`. - static inline void - _array__erase (Array *self, size_t element_size, uint32_t index) - { - assert (index < self->size); - char *contents = (char *)self->contents; - memmove (contents + index * element_size, - contents + (index + 1) * element_size, - (self->size - index - 1) * element_size); - self->size--; - } +/// This is not what you're looking for, see `array_erase`. +static inline void _array__erase(void* self_contents, uint32_t *size, + size_t element_size, uint32_t index) { + assert(index < *size); + char *contents = (char *)self_contents; + memmove(contents + index * element_size, contents + (index + 1) * element_size, + (*size - index - 1) * element_size); + (*size)--; +} - /// This is not what you're looking for, see `array_reserve`. - static inline void - _array__reserve (Array *self, size_t element_size, uint32_t new_capacity) - { - if (new_capacity > self->capacity) - { - if (self->contents) - { - self->contents - = ts_realloc (self->contents, new_capacity * element_size); - } - else - { - self->contents = ts_malloc (new_capacity * element_size); - } - self->capacity = new_capacity; - } +/// This is not what you're looking for, see `array_reserve`. +static inline void *_array__reserve(void *contents, uint32_t *capacity, + size_t element_size, uint32_t new_capacity) { + void *new_contents = contents; + if (new_capacity > *capacity) { + if (contents) { + new_contents = ts_realloc(contents, new_capacity * element_size); + } else { + new_contents = ts_malloc(new_capacity * element_size); + } + *capacity = new_capacity; } + return new_contents; +} - /// This is not what you're looking for, see `array_assign`. - static inline void - _array__assign (Array *self, const Array *other, size_t element_size) - { - _array__reserve (self, element_size, other->size); - self->size = other->size; - memcpy (self->contents, other->contents, self->size * element_size); - } +/// This is not what you're looking for, see `array_assign`. +static inline void *_array__assign(void* self_contents, uint32_t *self_size, uint32_t *self_capacity, + const void *other_contents, uint32_t other_size, size_t element_size) { + void *new_contents = _array__reserve(self_contents, self_capacity, element_size, other_size); + *self_size = other_size; + memcpy(new_contents, other_contents, *self_size * element_size); + return new_contents; +} - /// This is not what you're looking for, see `array_swap`. - static inline void - _array__swap (Array *self, Array *other) - { - Array swap = *other; - *other = *self; - *self = swap; - } +/// This is not what you're looking for, see `array_swap`. +static inline void _array__swap(uint32_t *self_size, uint32_t *self_capacity, + uint32_t *other_size, uint32_t *other_capacity) { + uint32_t tmp_size = *self_size; + uint32_t tmp_capacity = *self_capacity; + *self_size = *other_size; + *self_capacity = *other_capacity; + *other_size = tmp_size; + *other_capacity = tmp_capacity; +} - /// This is not what you're looking for, see `array_push` or `array_grow_by`. - static inline void - _array__grow (Array *self, uint32_t count, size_t element_size) - { - uint32_t new_size = self->size + count; - if (new_size > self->capacity) - { - uint32_t new_capacity = self->capacity * 2; - if (new_capacity < 8) - new_capacity = 8; - if (new_capacity < new_size) - new_capacity = new_size; - _array__reserve (self, element_size, new_capacity); - } +/// This is not what you're looking for, see `array_push` or `array_grow_by`. +static inline void *_array__grow(void *contents, uint32_t size, uint32_t *capacity, + uint32_t count, size_t element_size) { + void *new_contents = contents; + uint32_t new_size = size + count; + if (new_size > *capacity) { + uint32_t new_capacity = *capacity * 2; + if (new_capacity < 8) new_capacity = 8; + if (new_capacity < new_size) new_capacity = new_size; + new_contents = _array__reserve(contents, capacity, element_size, new_capacity); } + return new_contents; +} - /// This is not what you're looking for, see `array_splice`. - static inline void - _array__splice (Array *self, size_t element_size, uint32_t index, - uint32_t old_count, uint32_t new_count, const void *elements) - { - uint32_t new_size = self->size + new_count - old_count; - uint32_t old_end = index + old_count; - uint32_t new_end = index + new_count; - assert (old_end <= self->size); +/// This is not what you're looking for, see `array_splice`. +static inline void *_array__splice(void *self_contents, uint32_t *size, uint32_t *capacity, + size_t element_size, + uint32_t index, uint32_t old_count, + uint32_t new_count, const void *elements) { + uint32_t new_size = *size + new_count - old_count; + uint32_t old_end = index + old_count; + uint32_t new_end = index + new_count; + assert(old_end <= *size); - _array__reserve (self, element_size, new_size); + void *new_contents = _array__reserve(self_contents, capacity, element_size, new_size); - char *contents = (char *)self->contents; - if (self->size > old_end) - { - memmove (contents + new_end * element_size, - contents + old_end * element_size, - (self->size - old_end) * element_size); - } - if (new_count > 0) - { - if (elements) - { - memcpy ((contents + index * element_size), elements, - new_count * element_size); - } - else - { - memset ((contents + index * element_size), 0, - new_count * element_size); - } - } - self->size += new_count - old_count; + char *contents = (char *)new_contents; + if (*size > old_end) { + memmove( + contents + new_end * element_size, + contents + old_end * element_size, + (*size - old_end) * element_size + ); } + if (new_count > 0) { + if (elements) { + memcpy( + (contents + index * element_size), + elements, + new_count * element_size + ); + } else { + memset( + (contents + index * element_size), + 0, + new_count * element_size + ); + } + } + *size += new_count - old_count; + + return new_contents; +} /// A binary search routine, based on Rust's `std::slice::binary_search_by`. -/// This is not what you're looking for, see `array_search_sorted_with` or -/// `array_search_sorted_by`. -#define _array__search_sorted(self, start, compare, suffix, needle, _index, \ - _exists) \ - do \ - { \ - *(_index) = start; \ - *(_exists) = false; \ - uint32_t size = (self)->size - *(_index); \ - if (size == 0) \ - break; \ - int comparison; \ - while (size > 1) \ - { \ - uint32_t half_size = size / 2; \ - uint32_t mid_index = *(_index) + half_size; \ - comparison \ - = compare (&((self)->contents[mid_index] suffix), (needle)); \ - if (comparison <= 0) \ - *(_index) = mid_index; \ - size -= half_size; \ - } \ - comparison = compare (&((self)->contents[*(_index)] suffix), (needle)); \ - if (comparison == 0) \ - *(_exists) = true; \ - else if (comparison < 0) \ - *(_index) += 1; \ - } \ - while (0) +/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`. +#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \ + do { \ + *(_index) = start; \ + *(_exists) = false; \ + uint32_t size = (self)->size - *(_index); \ + if (size == 0) break; \ + int comparison; \ + while (size > 1) { \ + uint32_t half_size = size / 2; \ + uint32_t mid_index = *(_index) + half_size; \ + comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \ + if (comparison <= 0) *(_index) = mid_index; \ + size -= half_size; \ + } \ + comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \ + if (comparison == 0) *(_exists) = true; \ + else if (comparison < 0) *(_index) += 1; \ + } while (0) -/// Helper macro for the `_sorted_by` routines below. This takes the left -/// (existing) parameter by reference in order to work with the generic sorting -/// function above. +/// Helper macro for the `_sorted_by` routines below. This takes the left (existing) +/// parameter by reference in order to work with the generic sorting function above. #define _compare_int(a, b) ((int)*(a) - (int)(b)) #ifdef _MSC_VER -#pragma warning(default : 4101) +#pragma warning(pop) #elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif @@ -339,4 +327,4 @@ extern "C" } #endif -#endif // TREE_SITTER_ARRAY_H_ +#endif // TREE_SITTER_ARRAY_H_ diff --git a/tree-sitter-yts/src/tree_sitter/parser.h b/tree-sitter-yts/src/tree_sitter/parser.h index aec3b17..858107d 100644 --- a/tree-sitter-yts/src/tree_sitter/parser.h +++ b/tree-sitter-yts/src/tree_sitter/parser.h @@ -1,246 +1,231 @@ -/* - * yt - A fully featured command line YouTube client - * - * Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> - * SPDX-License-Identifier: GPL-3.0-or-later - * - * This file is part of Yt. - * - * You should have received a copy of the License along with this program. - * If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - */ - #ifndef TREE_SITTER_PARSER_H_ #define TREE_SITTER_PARSER_H_ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include <stdbool.h> #include <stdint.h> #include <stdlib.h> -#define ts_builtin_sym_error ((TSSymbol) - 1) +#define ts_builtin_sym_error ((TSSymbol)-1) #define ts_builtin_sym_end 0 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 #ifndef TREE_SITTER_API_H_ - typedef uint16_t TSStateId; - typedef uint16_t TSSymbol; - typedef uint16_t TSFieldId; - typedef struct TSLanguage TSLanguage; +typedef uint16_t TSStateId; +typedef uint16_t TSSymbol; +typedef uint16_t TSFieldId; +typedef struct TSLanguage TSLanguage; +typedef struct TSLanguageMetadata { + uint8_t major_version; + uint8_t minor_version; + uint8_t patch_version; +} TSLanguageMetadata; #endif - typedef struct - { - TSFieldId field_id; - uint8_t child_index; - bool inherited; - } TSFieldMapEntry; +typedef struct { + TSFieldId field_id; + uint8_t child_index; + bool inherited; +} TSFieldMapEntry; - typedef struct - { - uint16_t index; - uint16_t length; - } TSFieldMapSlice; +// Used to index the field and supertype maps. +typedef struct { + uint16_t index; + uint16_t length; +} TSMapSlice; - typedef struct - { - bool visible; - bool named; - bool supertype; - } TSSymbolMetadata; +typedef struct { + bool visible; + bool named; + bool supertype; +} TSSymbolMetadata; - typedef struct TSLexer TSLexer; +typedef struct TSLexer TSLexer; - struct TSLexer - { - int32_t lookahead; - TSSymbol result_symbol; - void (*advance) (TSLexer *, bool); - void (*mark_end) (TSLexer *); - uint32_t (*get_column) (TSLexer *); - bool (*is_at_included_range_start) (const TSLexer *); - bool (*eof) (const TSLexer *); - void (*log) (const TSLexer *, const char *, ...); - }; +struct TSLexer { + int32_t lookahead; + TSSymbol result_symbol; + void (*advance)(TSLexer *, bool); + void (*mark_end)(TSLexer *); + uint32_t (*get_column)(TSLexer *); + bool (*is_at_included_range_start)(const TSLexer *); + bool (*eof)(const TSLexer *); + void (*log)(const TSLexer *, const char *, ...); +}; - typedef enum - { - TSParseActionTypeShift, - TSParseActionTypeReduce, - TSParseActionTypeAccept, - TSParseActionTypeRecover, - } TSParseActionType; +typedef 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; +typedef union { + struct { + uint8_t type; + TSStateId state; + bool extra; + bool repetition; + } shift; + struct { uint8_t type; - } TSParseAction; + uint8_t child_count; + TSSymbol symbol; + int16_t dynamic_precedence; + uint16_t production_id; + } reduce; + uint8_t type; +} TSParseAction; - typedef struct - { - uint16_t lex_state; - uint16_t external_lex_state; - } TSLexMode; +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; +} TSLexMode; - typedef union - { - TSParseAction action; - struct - { - uint8_t count; - bool reusable; - } entry; - } TSParseActionEntry; +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; + uint16_t reserved_word_set_id; +} TSLexerMode; - typedef struct - { - int32_t start; - int32_t end; - } TSCharacterRange; +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; - }; +typedef struct { + int32_t start; + int32_t end; +} TSCharacterRange; - static inline bool - set_contains (TSCharacterRange *ranges, uint32_t len, int32_t lookahead) - { - uint32_t index = 0; - uint32_t size = len - index; - while (size > 1) - { - uint32_t half_size = size / 2; - uint32_t mid_index = index + half_size; - TSCharacterRange *range = &ranges[mid_index]; - if (lookahead >= range->start && lookahead <= range->end) - { - return true; - } - else if (lookahead > range->end) - { - index = mid_index; - } - size -= half_size; - } - TSCharacterRange *range = &ranges[index]; - return (lookahead >= range->start && lookahead <= range->end); +struct TSLanguage { + uint32_t abi_version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + uint32_t state_count; + uint32_t large_state_count; + uint32_t production_id_count; + uint32_t field_count; + uint16_t max_alias_sequence_length; + const uint16_t *parse_table; + const uint16_t *small_parse_table; + const uint32_t *small_parse_table_map; + const TSParseActionEntry *parse_actions; + const char * const *symbol_names; + const char * const *field_names; + const TSMapSlice *field_map_slices; + const TSFieldMapEntry *field_map_entries; + const TSSymbolMetadata *symbol_metadata; + const TSSymbol *public_symbol_map; + const uint16_t *alias_map; + const TSSymbol *alias_sequences; + const TSLexerMode *lex_modes; + bool (*lex_fn)(TSLexer *, TSStateId); + bool (*keyword_lex_fn)(TSLexer *, TSStateId); + TSSymbol keyword_capture_token; + struct { + const bool *states; + const TSSymbol *symbol_map; + void *(*create)(void); + void (*destroy)(void *); + bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); + unsigned (*serialize)(void *, char *); + void (*deserialize)(void *, const char *, unsigned); + } external_scanner; + const TSStateId *primary_state_ids; + const char *name; + const TSSymbol *reserved_words; + uint16_t max_reserved_word_set_size; + uint32_t supertype_count; + const TSSymbol *supertype_symbols; + const TSMapSlice *supertype_map_slices; + const TSSymbol *supertype_map_entries; + TSLanguageMetadata metadata; +}; + +static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { + uint32_t index = 0; + uint32_t size = len - index; + while (size > 1) { + uint32_t half_size = size / 2; + uint32_t mid_index = index + half_size; + const TSCharacterRange *range = &ranges[mid_index]; + if (lookahead >= range->start && lookahead <= range->end) { + return true; + } else if (lookahead > range->end) { + index = mid_index; + } + size -= half_size; } + const TSCharacterRange *range = &ranges[index]; + return (lookahead >= range->start && lookahead <= range->end); +} - /* - * Lexer Macros - */ +/* + * Lexer Macros + */ #ifdef _MSC_VER -#define UNUSED __pragma (warning (suppress : 4101)) +#define UNUSED __pragma(warning(suppress : 4101)) #else -#define UNUSED __attribute__ ((unused)) +#define UNUSED __attribute__((unused)) #endif -#define START_LEXER() \ - bool result = false; \ - bool skip = false; \ - UNUSED \ - bool eof = false; \ - int32_t lookahead; \ - goto start; \ - next_state: \ - lexer->advance (lexer, skip); \ - start: \ - skip = false; \ +#define START_LEXER() \ + bool result = false; \ + bool skip = false; \ + UNUSED \ + bool eof = false; \ + int32_t lookahead; \ + goto start; \ + next_state: \ + lexer->advance(lexer, skip); \ + start: \ + skip = false; \ lookahead = lexer->lookahead; -#define ADVANCE(state_value) \ - { \ - state = state_value; \ - goto next_state; \ +#define ADVANCE(state_value) \ + { \ + state = state_value; \ + goto next_state; \ } -#define ADVANCE_MAP(...) \ - { \ - static const uint16_t map[] = { __VA_ARGS__ }; \ - for (uint32_t i = 0; i < sizeof (map) / sizeof (map[0]); i += 2) \ - { \ - if (map[i] == lookahead) \ - { \ - state = map[i + 1]; \ - goto next_state; \ - } \ - } \ +#define ADVANCE_MAP(...) \ + { \ + static const uint16_t map[] = { __VA_ARGS__ }; \ + for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \ + if (map[i] == lookahead) { \ + state = map[i + 1]; \ + goto next_state; \ + } \ + } \ } -#define SKIP(state_value) \ - { \ - skip = true; \ - state = state_value; \ - goto next_state; \ +#define 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 ACCEPT_TOKEN(symbol_value) \ + result = true; \ + lexer->result_symbol = symbol_value; \ + lexer->mark_end(lexer); #define END_STATE() return result; - /* - * Parse Table Macros - */ +/* + * Parse Table Macros + */ #define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) @@ -248,57 +233,54 @@ extern "C" #define ACTIONS(id) id -#define SHIFT(state_value) \ - { \ - { \ - .shift = {.type = TSParseActionTypeShift, .state = (state_value) } \ - } \ - } +#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_REPEAT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = (state_value), \ + .repetition = true \ + } \ + }} -#define SHIFT_EXTRA() \ - { \ - { \ - .shift = {.type = TSParseActionTypeShift, .extra = true } \ - } \ - } +#define SHIFT_EXTRA() \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .extra = true \ + } \ + }} -#define REDUCE(symbol_name, children, precedence, prod_id) \ - { \ - { \ - .reduce = { .type = TSParseActionTypeReduce, \ - .symbol = symbol_name, \ - .child_count = children, \ - .dynamic_precedence = precedence, \ - .production_id = prod_id }, \ - } \ - } +#define REDUCE(symbol_name, children, precedence, prod_id) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_name, \ + .child_count = children, \ + .dynamic_precedence = precedence, \ + .production_id = prod_id \ + }, \ + }} -#define RECOVER() \ - { \ - { \ - .type = TSParseActionTypeRecover \ - } \ - } +#define RECOVER() \ + {{ \ + .type = TSParseActionTypeRecover \ + }} -#define ACCEPT_INPUT() \ - { \ - { \ - .type = TSParseActionTypeAccept \ - } \ - } +#define ACCEPT_INPUT() \ + {{ \ + .type = TSParseActionTypeAccept \ + }} #ifdef __cplusplus } #endif -#endif // TREE_SITTER_PARSER_H_ +#endif // TREE_SITTER_PARSER_H_ diff --git a/tree-sitter-yts/tree-sitter.json b/tree-sitter-yts/tree-sitter.json index f1a0586..33c2b6e 100644 --- a/tree-sitter-yts/tree-sitter.json +++ b/tree-sitter-yts/tree-sitter.json @@ -1,29 +1,40 @@ { + "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json", "grammars": [ { - "name": "yts", - "camelcase": "Yts", + "name": "YTS", + "camelcase": "YTS", + "title": "YTS", "scope": "source.yts", - "path": ".", - "file-types": ["yts"], - "highlights": ["queries/highlights.scm"], - "injection-regex": "^(yts)$" + "file-types": [ + "yts" + ], + "injection-regex": "^yts$", + "class-name": "TreeSitterYts" } ], "metadata": { - "version": "0.0.1", - "license": "MIT", - "description": "yts grammar for tree-sitter", + "version": "0.1.0", + "license": "GPL-3-or-later", + "description": "Parser for yt's selection language", + "authors": [ + { + "name": "Benedikt Peetz", + "email": "benedikt.peetz@b-peetz.de" + } + ], "links": { - "repository": "https://git.vhack.eu/soispha/clients/yt/tree-sitter-yts" + "repository": "https://git.foss-syndicate.org/bpeetz/clients/yt" } }, "bindings": { - "c": true, - "go": true, - "node": true, - "python": true, + "c": false, + "go": false, + "java": false, + "node": false, + "python": false, "rust": true, - "swift": true + "swift": false, + "zig": false } } diff --git a/tree-sitter-yts/tree-sitter.json.license b/tree-sitter-yts/tree-sitter.json.license deleted file mode 100644 index d4d410f..0000000 --- a/tree-sitter-yts/tree-sitter.json.license +++ /dev/null @@ -1,9 +0,0 @@ -yt - A fully featured command line YouTube client - -Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of Yt. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. |
