diff options
Diffstat (limited to '')
27 files changed, 2389 insertions, 1 deletions
diff --git a/sys/nixpkgs/pkgs/default.nix b/sys/nixpkgs/pkgs/default.nix index 3f9df3ed..5096f902 100644 --- a/sys/nixpkgs/pkgs/default.nix +++ b/sys/nixpkgs/pkgs/default.nix @@ -3,6 +3,7 @@ nvim_plugs = import ./plgs-pkgs; update_vim_plugins = import ./update_vim_plugins; ytc = import ./ytc; - overlays = [] ++ snap-sync-forked ++ nvim_plugs ++ update_vim_plugins ++ ytc; + yts-grammar = import ./tree-sitter-yts; + overlays = snap-sync-forked ++ nvim_plugs ++ update_vim_plugins ++ yts-grammar; in overlays diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/.editorconfig b/sys/nixpkgs/pkgs/tree-sitter-yts/.editorconfig new file mode 100644 index 00000000..919c78fa --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/.editorconfig @@ -0,0 +1,21 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = false + +# 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 + +[**.{js,json,cc,css}] +indent_style = space +indent_size = 2 + +# tree-sitter generate emits json with no trailing newline +[src/node-types.json] +insert_final_newline = false diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/.envrc b/sys/nixpkgs/pkgs/tree-sitter-yts/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/.envrc @@ -0,0 +1 @@ +use flake diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/.gitignore b/sys/nixpkgs/pkgs/tree-sitter-yts/.gitignore new file mode 100644 index 00000000..c4e2e389 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/.gitignore @@ -0,0 +1,3 @@ +/.direnv +/result +/node_modules diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/Cargo.toml b/sys/nixpkgs/pkgs/tree-sitter-yts/Cargo.toml new file mode 100644 index 00000000..9756d2fe --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/Cargo.toml @@ -0,0 +1,26 @@ +[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" + +build = "bindings/rust/build.rs" +include = [ + "bindings/rust/*", + "grammar.js", + "queries/*", + "src/*", +] + +[lib] +path = "bindings/rust/lib.rs" + +[dependencies] +tree-sitter = "~0.20.10" + +[build-dependencies] +cc = "1.0" diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/binding.gyp b/sys/nixpkgs/pkgs/tree-sitter-yts/binding.gyp new file mode 100644 index 00000000..b05038b4 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/binding.gyp @@ -0,0 +1,19 @@ +{ + "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/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/node/binding.cc b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/node/binding.cc new file mode 100644 index 00000000..de7d0497 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/node/binding.cc @@ -0,0 +1,28 @@ +#include "tree_sitter/parser.h" +#include <node.h> +#include "nan.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/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/node/index.js b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/node/index.js new file mode 100644 index 00000000..32179742 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/node/index.js @@ -0,0 +1,19 @@ +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/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/rust/build.rs b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/rust/build.rs new file mode 100644 index 00000000..c6061f09 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/rust/build.rs @@ -0,0 +1,40 @@ +fn main() { + let src_dir = std::path::Path::new("src"); + + let mut c_config = cc::Build::new(); + c_config.include(&src_dir); + c_config + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable") + .flag_if_supported("-Wno-trigraphs"); + let parser_path = src_dir.join("parser.c"); + c_config.file(&parser_path); + + // If your language uses an external scanner written in C, + // then include this block of code: + + /* + let scanner_path = src_dir.join("scanner.c"); + c_config.file(&scanner_path); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + */ + + c_config.compile("parser"); + println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); + + // If your language uses an external scanner written in C++, + // then include this block of code: + + /* + let mut cpp_config = cc::Build::new(); + cpp_config.cpp(true); + cpp_config.include(&src_dir); + cpp_config + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable"); + let scanner_path = src_dir.join("scanner.cc"); + cpp_config.file(&scanner_path); + cpp_config.compile("scanner"); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + */ +} diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/rust/lib.rs b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/rust/lib.rs new file mode 100644 index 00000000..f1868b2d --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/bindings/rust/lib.rs @@ -0,0 +1,52 @@ +//! 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: +//! +//! ``` +//! let code = ""; +//! let mut parser = tree_sitter::Parser::new(); +//! parser.set_language(tree_sitter_yts::language()).expect("Error loading yts grammar"); +//! let tree = parser.parse(code, None).unwrap(); +//! ``` +//! +//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +//! [language func]: fn.language.html +//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html +//! [tree-sitter]: https://tree-sitter.github.io/ + +use tree_sitter::Language; + +extern "C" { + fn tree_sitter_yts() -> Language; +} + +/// Get the tree-sitter [Language][] for this grammar. +/// +/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +pub fn language() -> Language { + unsafe { tree_sitter_yts() } +} + +/// The content of the [`node-types.json`][] file for this grammar. +/// +/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types +pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); + +// Uncomment these to include any queries that this grammar contains + +// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); +// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); +// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); +// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); + +#[cfg(test)] +mod tests { + #[test] + fn test_can_load_grammar() { + let mut parser = tree_sitter::Parser::new(); + parser + .set_language(super::language()) + .expect("Error loading yts language"); + } +} diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/comments.txt b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/comments.txt new file mode 100644 index 00000000..0070baf8 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/comments.txt @@ -0,0 +1,51 @@ +================================================================================ +Parse multiple lines +================================================================================ + +pick 6221 "Name" "2024-01-17" "A" "[0m 0s]" "url" +pick 6181 "Name2" "2024-01-16" "A2" "[0m 0s]" "url" + +# This is a comment +# it contains information + +-------------------------------------------------------------------------------- + +(source_file + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (comment) + (comment)) diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/comments_correct.txt b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/comments_correct.txt new file mode 100644 index 00000000..40cdab7d --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/comments_correct.txt @@ -0,0 +1,27 @@ +================================================================================ +Disregard comments in title +================================================================================ + +pick 6094 "#100 Name" "2024-01-12" "A" "[133m 29s]" "url" + +-------------------------------------------------------------------------------- + +(source_file + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote)))) diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/duration.txt b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/duration.txt new file mode 100644 index 00000000..59476b98 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/duration.txt @@ -0,0 +1,84 @@ +================================================================================ +Parse multiple lines with different durations +================================================================================ + +pick 6221 "Name" "2024-01-17" "A" "[1h 0m]" "url" +pick 6181 "Name2" "2024-01-16" "A2" "[20m 02s]" "url2" +pick 6184 "Name3" "2024-01-16" "A3" "[20h 0m]" "url3" +pick 6206 "Name4" "2024-01-16" "A4" "[No Duration]" "url4" + +-------------------------------------------------------------------------------- + +(source_file + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote)))) diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/url.txt b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/url.txt new file mode 100644 index 00000000..1ae3d106 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/corpus/url.txt @@ -0,0 +1,84 @@ +================================================================================ +Parse multiple lines with url +================================================================================ + +pick 6221 "Name" "2024-01-17" "A" "[0h 0m]" "url" +pick 6181 "Name2" "2024-01-16" "A2" "[0h 0m]" "url2" +pick 6184 "Name3" "2024-01-16" "A3" "[0h 0m]" "url3" +pick 6206 "Name4" "2024-01-16" "A4" "[0h 0m]" "url4" + +-------------------------------------------------------------------------------- + +(source_file + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote))) + (line + (command) + (id) + (title + (quote) + (quote)) + (date + (quote) + (quote)) + (author + (quote) + (quote)) + (duration + (quote) + (quote)) + (url + (quote) + (quote)))) diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/default.nix b/sys/nixpkgs/pkgs/tree-sitter-yts/default.nix new file mode 100644 index 00000000..7e15481c --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/default.nix @@ -0,0 +1,11 @@ +[ + ( + final: prev: { + yts-grammar = (prev.callPackage ./package.nix {}) { + language = "yts"; + version = "1.0"; + src = ./.; + }; + } + ) +] diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/flake.lock b/sys/nixpkgs/pkgs/tree-sitter-yts/flake.lock new file mode 100644 index 00000000..bff9f1fa --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/flake.lock @@ -0,0 +1,97 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": ["nixpkgs"] + }, + "locked": { + "lastModified": 1704819371, + "narHash": "sha256-oFUfPWrWGQTZaCM3byxwYwrMLwshDxVGOrMH5cVP/X8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "5c234301a1277e4cc759c23a2a7a00a06ddd7111", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1705133751, + "narHash": "sha256-rCIsyE80jgiOU78gCWN3A0wE0tR2GI5nH6MlS+HaaSQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b19f5e77dd906cb52dade0b7bd280339d2a1f3d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "npmlock2nix": { + "flake": false, + "locked": { + "lastModified": 1673447413, + "narHash": "sha256-sJM82Sj8yfQYs9axEmGZ9Evzdv/kDcI9sddqJ45frrU=", + "owner": "nix-community", + "repo": "npmlock2nix", + "rev": "9197bbf397d76059a76310523d45df10d2e4ca81", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "npmlock2nix", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "npmlock2nix": "npmlock2nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/flake.nix b/sys/nixpkgs/pkgs/tree-sitter-yts/flake.nix new file mode 100644 index 00000000..1b6f8ab0 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/flake.nix @@ -0,0 +1,82 @@ +{ + description = "tree-sitter-yts"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + flake-utils.url = "github:numtide/flake-utils"; + + npmlock2nix = { + url = "github:nix-community/npmlock2nix"; + flake = false; + }; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + npmlock2nix, + crane, + }: (flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; + + npmlock2nix' = pkgs.callPackage npmlock2nix {}; + craneLib = crane.lib.${system}; + in { + build = self.packages.${system}.tree-sitter-nix; + + rust-bindings = craneLib.buildPackage { + src = self; + }; + + # Requires xcode + node-bindings = npmlock2nix'.v2.build { + src = self; + inherit (self.devShells.${system}.default) nativeBuildInputs; + inherit (pkgs) nodejs; + + buildCommands = [ + "${pkgs.nodePackages.node-gyp}/bin/node-gyp configure" + "npm run build" + ]; + + installPhase = '' + touch $out + ''; + }; + + packages.tree-sitter-yts = (pkgs.callPackage ./grammar.nix {}) { + language = "yts"; + version = "1.0"; + src = self; + }; + + packages.default = self.packages.${system}.tree-sitter-yts; + devShells.default = pkgs.mkShell { + packages = [ + pkgs.nodejs + pkgs.python3 + + pkgs.tree-sitter + pkgs.editorconfig-checker + + pkgs.rustc + pkgs.cargo + + # Formatters + pkgs.treefmt + pkgs.nixpkgs-fmt + pkgs.nodePackages.prettier + pkgs.rustfmt + pkgs.clang-tools + ]; + }; + })); +} diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js b/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js new file mode 100644 index 00000000..722d6a44 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js @@ -0,0 +1,26 @@ +module.exports = grammar({ + name: "yts", + + rules: { + source_file: ($) => repeat(choice($.line, $.comment)), + line: ($) => + seq($.command, $.id, $.title, $.date, $.author, $.duration, $.url, "\n"), + + command: ($) => choice("pick", "watch", "drop", "p", "w", "d"), + id: ($) => /[0-9]+/, + title: ($) => seq($._q, /[^"]+/, $._q), + date: ($) => seq($._q, /\d{4}-\d{2}-\d{2}/, $._q), + author: ($) => seq($._q, /[^"]+/, $._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/, /\\\r?\n/], +}); diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/highlight.yts b/sys/nixpkgs/pkgs/tree-sitter-yts/highlight.yts new file mode 100644 index 00000000..319ee95c --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/highlight.yts @@ -0,0 +1,4 @@ +pick 6221 "Name" "2024-01-17" "A" "0:00" "url" +pick 6181 "Name2" "2024-01-16" "A2" "0:00" "url2" +pick 6184 "Name3" "2024-01-16" "A3" "0:00" "url3" +pick 6206 "Name4" "2024-01-16" "A4" "299:36" "url4" diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/package.json b/sys/nixpkgs/pkgs/tree-sitter-yts/package.json new file mode 100644 index 00000000..2511ccb7 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/package.json @@ -0,0 +1,31 @@ +{ + "name": "tree-sitter-yts", + "version": "0.0.1", + "description": "yts grammar for tree-sitter", + "main": "bindings/node", + "keywords": [ + "parsing", + "incremental" + ], + "dependencies": { + "nan": "^2.12.1" + }, + "devDependencies": { + "tree-sitter-cli": "^0.20.8" + }, + "scripts": { + "test": "tree-sitter test" + }, + "tree-sitter": [ + { + "scope": "source.yts", + "file-types": [ + "yts" + ], + "highlights": [ + "queries/highlights.scm" + ], + "injection-regex": "^(yts)$" + } + ] +} diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/package.nix b/sys/nixpkgs/pkgs/tree-sitter-yts/package.nix new file mode 100644 index 00000000..fe9a7326 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/package.nix @@ -0,0 +1,63 @@ +# taken from nixpgks: pkgs/development/tools/parsing/tree-sitter/grammar.nix +{ + stdenv, + nodejs, + tree-sitter, + lib, +}: +# Build a parser grammar and put the resulting shared object in `$out/parser` +{ + # language name + language, + version, + src, + location ? null, + generate ? false, + ... +} @ args: +stdenv.mkDerivation ({ + pname = "${language}-grammar"; + + inherit src version; + + nativeBuildInputs = lib.optionals generate [nodejs tree-sitter]; + + CFLAGS = ["-Isrc" "-O2"]; + CXXFLAGS = ["-Isrc" "-O2"]; + + stripDebugList = ["parser"]; + + configurePhase = + lib.optionalString (location != null) '' + cd ${location} + '' + + lib.optionalString generate '' + 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 + ''; + } + // removeAttrs args ["language" "location" "generate"]) diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/queries/highlights.scm b/sys/nixpkgs/pkgs/tree-sitter-yts/queries/highlights.scm new file mode 100644 index 00000000..674cbf18 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/queries/highlights.scm @@ -0,0 +1,11 @@ +(command) @keyword +(id) @constant +(title) @text.title +(date) @number +(author) @operator +(duration) @property +((url) @conceal (#set! conceal "")) + + +((quote) @conceal (#set! conceal "")) +(comment) @comment @spell diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json b/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json new file mode 100644 index 00000000..4157fde6 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json @@ -0,0 +1,230 @@ +{ + "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": "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": "watch" + }, + { + "type": "STRING", + "value": "drop" + }, + { + "type": "STRING", + "value": "p" + }, + { + "type": "STRING", + "value": "w" + }, + { + "type": "STRING", + "value": "d" + } + ] + }, + "id": { + "type": "PATTERN", + "value": "[0-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": "PATTERN", + "value": "\\d{4}-\\d{2}-\\d{2}" + }, + { + "type": "SYMBOL", + "name": "_q" + } + ] + }, + "author": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_q" + }, + { + "type": "PATTERN", + "value": "[^\"]+" + }, + { + "type": "SYMBOL", + "name": "_q" + } + ] + }, + "duration": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_q" + }, + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "No Duration" + }, + { + "type": "PATTERN", + "value": "\\d+m \\d+s" + }, + { + "type": "PATTERN", + "value": "\\d+h \\d+m" + } + ] + }, + { + "type": "STRING", + "value": "]" + } + ] + }, + { + "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": "\"" + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "\\s" + }, + { + "type": "PATTERN", + "value": "\\\\\\r?\\n" + } + ], + "conflicts": [], + "precedences": [], + "externals": [], + "inline": [], + "supertypes": [] +} + diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json b/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json new file mode 100644 index 00000000..1dcd3402 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json @@ -0,0 +1,192 @@ +[ + { + "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": "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": "id", + "named": true + }, + { + "type": "title", + "named": true + }, + { + "type": "url", + "named": true + } + ] + } + }, + { + "type": "source_file", + "named": 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 Duration", + "named": false + }, + { + "type": "[", + "named": false + }, + { + "type": "]", + "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": "w", + "named": false + }, + { + "type": "watch", + "named": false + } +] \ No newline at end of file diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c b/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c new file mode 100644 index 00000000..fc86808b --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c @@ -0,0 +1,926 @@ +#include <tree_sitter/parser.h> + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#define LANGUAGE_VERSION 14 +#define STATE_COUNT 31 +#define LARGE_STATE_COUNT 2 +#define SYMBOL_COUNT 28 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 18 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 0 +#define MAX_ALIAS_SEQUENCE_LENGTH 8 +#define PRODUCTION_ID_COUNT 1 + +enum { + anon_sym_LF = 1, + anon_sym_pick = 2, + anon_sym_watch = 3, + anon_sym_drop = 4, + anon_sym_p = 5, + anon_sym_w = 6, + anon_sym_d = 7, + sym_id = 8, + aux_sym_title_token1 = 9, + aux_sym_date_token1 = 10, + anon_sym_LBRACK = 11, + anon_sym_NoDuration = 12, + aux_sym_duration_token1 = 13, + aux_sym_duration_token2 = 14, + anon_sym_RBRACK = 15, + sym_comment = 16, + sym_quote = 17, + sym_source_file = 18, + sym_line = 19, + sym_command = 20, + sym_title = 21, + sym_date = 22, + sym_author = 23, + sym_duration = 24, + sym_url = 25, + sym__q = 26, + aux_sym_source_file_repeat1 = 27, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [anon_sym_LF] = "\n", + [anon_sym_pick] = "pick", + [anon_sym_watch] = "watch", + [anon_sym_drop] = "drop", + [anon_sym_p] = "p", + [anon_sym_w] = "w", + [anon_sym_d] = "d", + [sym_id] = "id", + [aux_sym_title_token1] = "title_token1", + [aux_sym_date_token1] = "date_token1", + [anon_sym_LBRACK] = "[", + [anon_sym_NoDuration] = "No Duration", + [aux_sym_duration_token1] = "duration_token1", + [aux_sym_duration_token2] = "duration_token2", + [anon_sym_RBRACK] = "]", + [sym_comment] = "comment", + [sym_quote] = "quote", + [sym_source_file] = "source_file", + [sym_line] = "line", + [sym_command] = "command", + [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", +}; + +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_watch] = anon_sym_watch, + [anon_sym_drop] = anon_sym_drop, + [anon_sym_p] = anon_sym_p, + [anon_sym_w] = anon_sym_w, + [anon_sym_d] = anon_sym_d, + [sym_id] = sym_id, + [aux_sym_title_token1] = aux_sym_title_token1, + [aux_sym_date_token1] = aux_sym_date_token1, + [anon_sym_LBRACK] = anon_sym_LBRACK, + [anon_sym_NoDuration] = anon_sym_NoDuration, + [aux_sym_duration_token1] = aux_sym_duration_token1, + [aux_sym_duration_token2] = aux_sym_duration_token2, + [anon_sym_RBRACK] = anon_sym_RBRACK, + [sym_comment] = sym_comment, + [sym_quote] = sym_quote, + [sym_source_file] = sym_source_file, + [sym_line] = sym_line, + [sym_command] = sym_command, + [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, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [anon_sym_LF] = { + .visible = true, + .named = false, + }, + [anon_sym_pick] = { + .visible = true, + .named = false, + }, + [anon_sym_watch] = { + .visible = true, + .named = false, + }, + [anon_sym_drop] = { + .visible = true, + .named = false, + }, + [anon_sym_p] = { + .visible = true, + .named = false, + }, + [anon_sym_w] = { + .visible = true, + .named = false, + }, + [anon_sym_d] = { + .visible = true, + .named = false, + }, + [sym_id] = { + .visible = true, + .named = true, + }, + [aux_sym_title_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_date_token1] = { + .visible = false, + .named = false, + }, + [anon_sym_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_NoDuration] = { + .visible = true, + .named = false, + }, + [aux_sym_duration_token1] = { + .visible = false, + .named = false, + }, + [aux_sym_duration_token2] = { + .visible = false, + .named = false, + }, + [anon_sym_RBRACK] = { + .visible = true, + .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_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, + }, +}; + +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, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(46); + if (lookahead == '"') ADVANCE(71); + if (lookahead == '#') ADVANCE(70); + if (lookahead == 'N') ADVANCE(29); + if (lookahead == '[') ADVANCE(65); + if (lookahead == '\\') SKIP(45) + if (lookahead == ']') ADVANCE(69); + if (lookahead == 'd') ADVANCE(53); + if (lookahead == 'p') ADVANCE(51); + if (lookahead == 'w') ADVANCE(52); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(0) + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(57); + END_STATE(); + case 1: + if (lookahead == '\n') SKIP(14) + END_STATE(); + case 2: + if (lookahead == '\n') SKIP(14) + if (lookahead == '\r') SKIP(1) + END_STATE(); + case 3: + if (lookahead == '\n') SKIP(16) + END_STATE(); + case 4: + if (lookahead == '\n') SKIP(16) + if (lookahead == '\r') SKIP(3) + END_STATE(); + case 5: + if (lookahead == '\n') SKIP(7) + END_STATE(); + case 6: + if (lookahead == '\n') SKIP(7) + if (lookahead == '\r') SKIP(5) + END_STATE(); + case 7: + if (lookahead == '\n') ADVANCE(47); + if (lookahead == '\\') SKIP(6) + if (lookahead == '\t' || + lookahead == '\r' || + lookahead == ' ') SKIP(7) + END_STATE(); + case 8: + if (lookahead == ' ') ADVANCE(13); + END_STATE(); + case 9: + if (lookahead == ' ') ADVANCE(38); + END_STATE(); + case 10: + if (lookahead == ' ') ADVANCE(39); + END_STATE(); + case 11: + if (lookahead == '-') ADVANCE(42); + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(24); + END_STATE(); + case 12: + if (lookahead == '-') ADVANCE(43); + END_STATE(); + case 13: + if (lookahead == 'D') ADVANCE(37); + END_STATE(); + case 14: + if (lookahead == 'N') ADVANCE(29); + if (lookahead == '\\') SKIP(2) + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(14) + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(23); + END_STATE(); + case 15: + if (lookahead == '\\') ADVANCE(60); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') ADVANCE(62); + if (lookahead != 0 && + lookahead != '"') ADVANCE(63); + END_STATE(); + case 16: + if (lookahead == '\\') SKIP(4) + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') SKIP(16) + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(59); + END_STATE(); + case 17: + if (lookahead == 'a') ADVANCE(35); + END_STATE(); + case 18: + if (lookahead == 'c') ADVANCE(26); + END_STATE(); + case 19: + if (lookahead == 'c') ADVANCE(20); + END_STATE(); + case 20: + if (lookahead == 'h') ADVANCE(49); + END_STATE(); + case 21: + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(11); + END_STATE(); + case 22: + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(21); + END_STATE(); + case 23: + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(22); + END_STATE(); + case 24: + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(24); + END_STATE(); + case 25: + if (lookahead == 'i') ADVANCE(31); + END_STATE(); + case 26: + if (lookahead == 'k') ADVANCE(48); + END_STATE(); + case 27: + if (lookahead == 'm') ADVANCE(68); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(27); + END_STATE(); + case 28: + if (lookahead == 'n') ADVANCE(66); + END_STATE(); + case 29: + if (lookahead == 'o') ADVANCE(8); + END_STATE(); + case 30: + if (lookahead == 'o') ADVANCE(32); + END_STATE(); + case 31: + if (lookahead == 'o') ADVANCE(28); + END_STATE(); + case 32: + if (lookahead == 'p') ADVANCE(50); + END_STATE(); + case 33: + if (lookahead == 'r') ADVANCE(17); + END_STATE(); + case 34: + if (lookahead == 's') ADVANCE(67); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34); + END_STATE(); + case 35: + if (lookahead == 't') ADVANCE(25); + END_STATE(); + case 36: + if (lookahead == 't') ADVANCE(19); + END_STATE(); + case 37: + if (lookahead == 'u') ADVANCE(33); + END_STATE(); + case 38: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(27); + END_STATE(); + case 39: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34); + END_STATE(); + case 40: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12); + END_STATE(); + case 41: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(64); + END_STATE(); + case 42: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(40); + END_STATE(); + case 43: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(41); + END_STATE(); + case 44: + if (eof) ADVANCE(46); + if (lookahead == '\n') SKIP(0) + END_STATE(); + case 45: + if (eof) ADVANCE(46); + if (lookahead == '\n') SKIP(0) + if (lookahead == '\r') SKIP(44) + END_STATE(); + case 46: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 47: + ACCEPT_TOKEN(anon_sym_LF); + if (lookahead == '\n') ADVANCE(47); + END_STATE(); + case 48: + ACCEPT_TOKEN(anon_sym_pick); + END_STATE(); + case 49: + ACCEPT_TOKEN(anon_sym_watch); + END_STATE(); + case 50: + ACCEPT_TOKEN(anon_sym_drop); + END_STATE(); + case 51: + ACCEPT_TOKEN(anon_sym_p); + if (lookahead == 'i') ADVANCE(18); + END_STATE(); + case 52: + ACCEPT_TOKEN(anon_sym_w); + if (lookahead == 'a') ADVANCE(36); + END_STATE(); + case 53: + ACCEPT_TOKEN(anon_sym_d); + if (lookahead == 'r') ADVANCE(30); + END_STATE(); + case 54: + ACCEPT_TOKEN(sym_id); + if (lookahead == '-') ADVANCE(42); + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(58); + END_STATE(); + case 55: + ACCEPT_TOKEN(sym_id); + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(54); + END_STATE(); + case 56: + ACCEPT_TOKEN(sym_id); + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(55); + END_STATE(); + case 57: + ACCEPT_TOKEN(sym_id); + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(56); + END_STATE(); + case 58: + ACCEPT_TOKEN(sym_id); + if (lookahead == 'h') ADVANCE(9); + if (lookahead == 'm') ADVANCE(10); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(58); + END_STATE(); + case 59: + ACCEPT_TOKEN(sym_id); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(59); + END_STATE(); + case 60: + ACCEPT_TOKEN(aux_sym_title_token1); + if (lookahead == '\n') ADVANCE(62); + if (lookahead == '\r') ADVANCE(61); + if (lookahead != 0 && + lookahead != '"') ADVANCE(63); + END_STATE(); + case 61: + ACCEPT_TOKEN(aux_sym_title_token1); + if (lookahead == '\n') ADVANCE(62); + if (lookahead != 0 && + lookahead != '"') ADVANCE(63); + END_STATE(); + case 62: + ACCEPT_TOKEN(aux_sym_title_token1); + if (lookahead == '\\') ADVANCE(60); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') ADVANCE(62); + if (lookahead != 0 && + lookahead != '"') ADVANCE(63); + END_STATE(); + case 63: + ACCEPT_TOKEN(aux_sym_title_token1); + if (lookahead != 0 && + lookahead != '"') ADVANCE(63); + END_STATE(); + case 64: + ACCEPT_TOKEN(aux_sym_date_token1); + END_STATE(); + case 65: + ACCEPT_TOKEN(anon_sym_LBRACK); + END_STATE(); + case 66: + ACCEPT_TOKEN(anon_sym_NoDuration); + END_STATE(); + case 67: + ACCEPT_TOKEN(aux_sym_duration_token1); + END_STATE(); + case 68: + ACCEPT_TOKEN(aux_sym_duration_token2); + END_STATE(); + case 69: + ACCEPT_TOKEN(anon_sym_RBRACK); + END_STATE(); + case 70: + ACCEPT_TOKEN(sym_comment); + if (lookahead != 0 && + lookahead != '\n') ADVANCE(70); + END_STATE(); + case 71: + ACCEPT_TOKEN(sym_quote); + 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 = 0}, + [5] = {.lex_state = 0}, + [6] = {.lex_state = 0}, + [7] = {.lex_state = 0}, + [8] = {.lex_state = 14}, + [9] = {.lex_state = 0}, + [10] = {.lex_state = 0}, + [11] = {.lex_state = 0}, + [12] = {.lex_state = 0}, + [13] = {.lex_state = 0}, + [14] = {.lex_state = 0}, + [15] = {.lex_state = 0}, + [16] = {.lex_state = 15}, + [17] = {.lex_state = 0}, + [18] = {.lex_state = 0}, + [19] = {.lex_state = 16}, + [20] = {.lex_state = 0}, + [21] = {.lex_state = 7}, + [22] = {.lex_state = 15}, + [23] = {.lex_state = 14}, + [24] = {.lex_state = 0}, + [25] = {.lex_state = 15}, + [26] = {.lex_state = 16}, + [27] = {.lex_state = 0}, + [28] = {.lex_state = 7}, + [29] = {.lex_state = 0}, + [30] = {.lex_state = 0}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [0] = { + [ts_builtin_sym_end] = ACTIONS(1), + [anon_sym_pick] = ACTIONS(1), + [anon_sym_watch] = ACTIONS(1), + [anon_sym_drop] = ACTIONS(1), + [anon_sym_p] = ACTIONS(1), + [anon_sym_w] = ACTIONS(1), + [anon_sym_d] = ACTIONS(1), + [sym_id] = ACTIONS(1), + [aux_sym_date_token1] = ACTIONS(1), + [anon_sym_LBRACK] = ACTIONS(1), + [anon_sym_NoDuration] = ACTIONS(1), + [aux_sym_duration_token1] = ACTIONS(1), + [aux_sym_duration_token2] = ACTIONS(1), + [anon_sym_RBRACK] = ACTIONS(1), + [sym_comment] = ACTIONS(1), + [sym_quote] = ACTIONS(1), + }, + [1] = { + [sym_source_file] = STATE(29), + [sym_line] = STATE(2), + [sym_command] = STATE(26), + [aux_sym_source_file_repeat1] = STATE(2), + [ts_builtin_sym_end] = ACTIONS(3), + [anon_sym_pick] = ACTIONS(5), + [anon_sym_watch] = ACTIONS(5), + [anon_sym_drop] = ACTIONS(5), + [anon_sym_p] = ACTIONS(7), + [anon_sym_w] = ACTIONS(7), + [anon_sym_d] = ACTIONS(7), + [sym_comment] = ACTIONS(9), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 6, + ACTIONS(11), 1, + ts_builtin_sym_end, + ACTIONS(13), 1, + sym_comment, + STATE(26), 1, + sym_command, + STATE(3), 2, + sym_line, + aux_sym_source_file_repeat1, + ACTIONS(5), 3, + anon_sym_pick, + anon_sym_watch, + anon_sym_drop, + ACTIONS(7), 3, + anon_sym_p, + anon_sym_w, + anon_sym_d, + [24] = 6, + ACTIONS(15), 1, + ts_builtin_sym_end, + ACTIONS(23), 1, + sym_comment, + STATE(26), 1, + sym_command, + STATE(3), 2, + sym_line, + aux_sym_source_file_repeat1, + ACTIONS(17), 3, + anon_sym_pick, + anon_sym_watch, + anon_sym_drop, + ACTIONS(20), 3, + anon_sym_p, + anon_sym_w, + anon_sym_d, + [48] = 2, + ACTIONS(28), 3, + anon_sym_p, + anon_sym_w, + anon_sym_d, + ACTIONS(26), 5, + ts_builtin_sym_end, + anon_sym_pick, + anon_sym_watch, + anon_sym_drop, + sym_comment, + [61] = 3, + ACTIONS(30), 1, + sym_quote, + STATE(21), 1, + sym_url, + STATE(22), 1, + sym__q, + [71] = 3, + ACTIONS(32), 1, + sym_quote, + STATE(7), 1, + sym_title, + STATE(25), 1, + sym__q, + [81] = 3, + ACTIONS(34), 1, + sym_quote, + STATE(9), 1, + sym_date, + STATE(23), 1, + sym__q, + [91] = 1, + ACTIONS(36), 3, + anon_sym_NoDuration, + aux_sym_duration_token1, + aux_sym_duration_token2, + [97] = 3, + ACTIONS(38), 1, + sym_quote, + STATE(10), 1, + sym_author, + STATE(16), 1, + sym__q, + [107] = 3, + ACTIONS(40), 1, + sym_quote, + STATE(5), 1, + sym_duration, + STATE(18), 1, + sym__q, + [117] = 2, + ACTIONS(42), 1, + sym_quote, + STATE(30), 1, + sym__q, + [124] = 2, + ACTIONS(44), 1, + sym_quote, + STATE(28), 1, + sym__q, + [131] = 2, + ACTIONS(46), 1, + sym_quote, + STATE(24), 1, + sym__q, + [138] = 2, + ACTIONS(48), 1, + sym_quote, + STATE(17), 1, + sym__q, + [145] = 2, + ACTIONS(50), 1, + sym_quote, + STATE(20), 1, + sym__q, + [152] = 1, + ACTIONS(52), 1, + aux_sym_title_token1, + [156] = 1, + ACTIONS(54), 1, + sym_quote, + [160] = 1, + ACTIONS(56), 1, + anon_sym_LBRACK, + [164] = 1, + ACTIONS(58), 1, + sym_id, + [168] = 1, + ACTIONS(60), 1, + sym_quote, + [172] = 1, + ACTIONS(62), 1, + anon_sym_LF, + [176] = 1, + ACTIONS(64), 1, + aux_sym_title_token1, + [180] = 1, + ACTIONS(66), 1, + aux_sym_date_token1, + [184] = 1, + ACTIONS(68), 1, + sym_quote, + [188] = 1, + ACTIONS(70), 1, + aux_sym_title_token1, + [192] = 1, + ACTIONS(72), 1, + sym_id, + [196] = 1, + ACTIONS(74), 1, + anon_sym_RBRACK, + [200] = 1, + ACTIONS(76), 1, + anon_sym_LF, + [204] = 1, + ACTIONS(78), 1, + ts_builtin_sym_end, + [208] = 1, + ACTIONS(80), 1, + sym_quote, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(2)] = 0, + [SMALL_STATE(3)] = 24, + [SMALL_STATE(4)] = 48, + [SMALL_STATE(5)] = 61, + [SMALL_STATE(6)] = 71, + [SMALL_STATE(7)] = 81, + [SMALL_STATE(8)] = 91, + [SMALL_STATE(9)] = 97, + [SMALL_STATE(10)] = 107, + [SMALL_STATE(11)] = 117, + [SMALL_STATE(12)] = 124, + [SMALL_STATE(13)] = 131, + [SMALL_STATE(14)] = 138, + [SMALL_STATE(15)] = 145, + [SMALL_STATE(16)] = 152, + [SMALL_STATE(17)] = 156, + [SMALL_STATE(18)] = 160, + [SMALL_STATE(19)] = 164, + [SMALL_STATE(20)] = 168, + [SMALL_STATE(21)] = 172, + [SMALL_STATE(22)] = 176, + [SMALL_STATE(23)] = 180, + [SMALL_STATE(24)] = 184, + [SMALL_STATE(25)] = 188, + [SMALL_STATE(26)] = 192, + [SMALL_STATE(27)] = 196, + [SMALL_STATE(28)] = 200, + [SMALL_STATE(29)] = 204, + [SMALL_STATE(30)] = 208, +}; + +static const TSParseActionEntry ts_parse_actions[] = { + [0] = {.entry = {.count = 0, .reusable = false}}, + [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), + [3] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 0), + [5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), + [7] = {.entry = {.count = 1, .reusable = false}}, SHIFT(19), + [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), + [11] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1), + [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), + [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), + [17] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(19), + [20] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(19), + [23] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(3), + [26] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_line, 8), + [28] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_line, 8), + [30] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), + [32] = {.entry = {.count = 1, .reusable = true}}, SHIFT(25), + [34] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), + [36] = {.entry = {.count = 1, .reusable = true}}, SHIFT(27), + [38] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), + [40] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), + [42] = {.entry = {.count = 1, .reusable = true}}, SHIFT(30), + [44] = {.entry = {.count = 1, .reusable = true}}, SHIFT(28), + [46] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), + [48] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), + [50] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [52] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [54] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_title, 3), + [56] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), + [58] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_command, 1), + [60] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_date, 3), + [62] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [64] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [66] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), + [68] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_author, 3), + [70] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), + [72] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6), + [74] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [76] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_url, 3), + [78] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [80] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_duration, 5), +}; + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef _WIN32 +#define extern __declspec(dllexport) +#endif + +extern 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; +} +#ifdef __cplusplus +} +#endif diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/tree_sitter/parser.h b/sys/nixpkgs/pkgs/tree-sitter-yts/src/tree_sitter/parser.h new file mode 100644 index 00000000..2b14ac10 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/tree_sitter/parser.h @@ -0,0 +1,224 @@ +#ifndef TREE_SITTER_PARSER_H_ +#define TREE_SITTER_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#define ts_builtin_sym_error ((TSSymbol)-1) +#define ts_builtin_sym_end 0 +#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 + +typedef uint16_t TSStateId; + +#ifndef TREE_SITTER_API_H_ +typedef uint16_t TSSymbol; +typedef uint16_t TSFieldId; +typedef struct TSLanguage TSLanguage; +#endif + +typedef struct { + TSFieldId field_id; + uint8_t child_index; + bool inherited; +} TSFieldMapEntry; + +typedef struct { + uint16_t index; + uint16_t length; +} TSFieldMapSlice; + +typedef struct { + bool visible; + bool named; + bool supertype; +} TSSymbolMetadata; + +typedef struct TSLexer TSLexer; + +struct TSLexer { + int32_t lookahead; + TSSymbol result_symbol; + void (*advance)(TSLexer *, bool); + void (*mark_end)(TSLexer *); + uint32_t (*get_column)(TSLexer *); + bool (*is_at_included_range_start)(const TSLexer *); + bool (*eof)(const TSLexer *); +}; + +typedef enum { + TSParseActionTypeShift, + TSParseActionTypeReduce, + TSParseActionTypeAccept, + TSParseActionTypeRecover, +} TSParseActionType; + +typedef union { + struct { + uint8_t type; + TSStateId state; + bool extra; + bool repetition; + } shift; + struct { + uint8_t type; + uint8_t child_count; + TSSymbol symbol; + int16_t dynamic_precedence; + uint16_t production_id; + } reduce; + uint8_t type; +} TSParseAction; + +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; +} TSLexMode; + +typedef union { + TSParseAction action; + struct { + uint8_t count; + bool reusable; + } entry; +} TSParseActionEntry; + +struct TSLanguage { + uint32_t version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + uint32_t state_count; + uint32_t large_state_count; + uint32_t production_id_count; + uint32_t field_count; + uint16_t max_alias_sequence_length; + const uint16_t *parse_table; + const uint16_t *small_parse_table; + const uint32_t *small_parse_table_map; + const TSParseActionEntry *parse_actions; + const char * const *symbol_names; + const char * const *field_names; + const TSFieldMapSlice *field_map_slices; + const TSFieldMapEntry *field_map_entries; + const TSSymbolMetadata *symbol_metadata; + const TSSymbol *public_symbol_map; + const uint16_t *alias_map; + const TSSymbol *alias_sequences; + const TSLexMode *lex_modes; + bool (*lex_fn)(TSLexer *, TSStateId); + bool (*keyword_lex_fn)(TSLexer *, TSStateId); + TSSymbol keyword_capture_token; + struct { + const bool *states; + const TSSymbol *symbol_map; + void *(*create)(void); + void (*destroy)(void *); + bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); + unsigned (*serialize)(void *, char *); + void (*deserialize)(void *, const char *, unsigned); + } external_scanner; + const TSStateId *primary_state_ids; +}; + +/* + * Lexer Macros + */ + +#define START_LEXER() \ + bool result = false; \ + bool skip = false; \ + bool eof = false; \ + int32_t lookahead; \ + goto start; \ + next_state: \ + lexer->advance(lexer, skip); \ + start: \ + skip = false; \ + lookahead = lexer->lookahead; + +#define ADVANCE(state_value) \ + { \ + state = state_value; \ + goto next_state; \ + } + +#define SKIP(state_value) \ + { \ + skip = true; \ + state = state_value; \ + goto next_state; \ + } + +#define ACCEPT_TOKEN(symbol_value) \ + result = true; \ + lexer->result_symbol = symbol_value; \ + lexer->mark_end(lexer); + +#define END_STATE() return result; + +/* + * Parse Table Macros + */ + +#define SMALL_STATE(id) id - LARGE_STATE_COUNT + +#define STATE(id) id + +#define ACTIONS(id) id + +#define SHIFT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = state_value \ + } \ + }} + +#define SHIFT_REPEAT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = state_value, \ + .repetition = true \ + } \ + }} + +#define SHIFT_EXTRA() \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .extra = true \ + } \ + }} + +#define REDUCE(symbol_val, child_count_val, ...) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_val, \ + .child_count = child_count_val, \ + __VA_ARGS__ \ + }, \ + }} + +#define RECOVER() \ + {{ \ + .type = TSParseActionTypeRecover \ + }} + +#define ACCEPT_INPUT() \ + {{ \ + .type = TSParseActionTypeAccept \ + }} + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_ diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/treefmt.toml b/sys/nixpkgs/pkgs/tree-sitter-yts/treefmt.toml new file mode 100644 index 00000000..e84ae516 --- /dev/null +++ b/sys/nixpkgs/pkgs/tree-sitter-yts/treefmt.toml @@ -0,0 +1,35 @@ +[formatter.nix] +command = "nixpkgs-fmt" +includes = ["*.nix"] +excludes = ["test/**.nix"] + +[formatter.prettier] +command = "prettier" +options = ["--write"] +includes = [ + "*.css", + "*.html", + "*.js", + "*.json", + "*.jsx", + "*.md", + "*.mdx", + "*.scss", + "*.ts", +] +excludes = ["src/**.json"] + +[formatter.rust] +command = "rustfmt" +options = ["--edition", "2018"] +includes = ["*.rs"] + +[formatter.c] +command = "clang-format" +options = [ "-i" ] +includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp" ] +excludes = [ + "bindings/node/binding.cc", + "src/parser.c", + "src/tree_sitter/parser.h", +] |