From 6a5426e063cc59f4775cc879b9d2e803da491f02 Mon Sep 17 00:00:00 2001 From: Rodion Goritskov Date: Sun, 3 Mar 2024 20:54:22 +0400 Subject: Add tree-sitter-yaml --- rodion/packages/tree-sitter.scm | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rodion/packages/tree-sitter.scm (limited to 'rodion/packages') diff --git a/rodion/packages/tree-sitter.scm b/rodion/packages/tree-sitter.scm new file mode 100644 index 0000000..ab5fd56 --- /dev/null +++ b/rodion/packages/tree-sitter.scm @@ -0,0 +1,75 @@ +(define-module (rodion packages tree-sitter) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (guix packages) + #:use-module (guix git-download) + #:use-module (guix gexp) + #:use-module (guix build-system tree-sitter) + #:use-module (guix build utils)) + +(define (tree-sitter-delete-generated-files grammar-directories) + #~(begin + (use-modules (guix build utils)) + (delete-file "binding.gyp") + (delete-file-recursively "bindings") + (for-each + (lambda (lang) + (with-directory-excursion lang + (delete-file "src/grammar.json") + (delete-file "src/node-types.json") + (delete-file "src/parser.c") + (delete-file-recursively "src/tree_sitter"))) + '#$grammar-directories))) + +(define* (tree-sitter-grammar + name text hash version + #:key + (commit (string-append "v" version)) + (repository-url + (format #f "https://github.com/tree-sitter/tree-sitter-~a" name)) + (grammar-directories '(".")) + (article "a") + (inputs '()) + (get-cleanup-snippet tree-sitter-delete-generated-files) + (license license:expat)) + "Returns a package for Tree-sitter grammar. NAME will be used with +tree-sitter- prefix to generate package name and also for generating +REPOSITORY-URL value if it's not specified explicitly, TEXT is a string which +will be used in description and synopsis. GET-CLEANUP-SNIPPET is a function, +it recieves GRAMMAR-DIRECTORIES as an argument and should return a G-exp, +which will be used as a snippet in origin." + (let* ((multiple? (> (length grammar-directories) 1)) + (grammar-names (string-append text " grammar" (if multiple? "s" ""))) + (synopsis (string-append "Tree-sitter " grammar-names)) + (description + (string-append "This package provides " + (if multiple? "" article) (if multiple? "" " ") + grammar-names " for the Tree-sitter library.")) + (name (string-append "tree-sitter-" name))) + (package + (name name) + (version version) + (home-page repository-url) + (source (origin + (method git-fetch) + (uri (git-reference + (url repository-url) + (commit commit))) + (file-name (git-file-name name version)) + (sha256 (base32 hash)) + (snippet + (get-cleanup-snippet grammar-directories)))) + (build-system tree-sitter-build-system) + (arguments (list + #:grammar-directories grammar-directories + #:tests? #f)) + (inputs inputs) + (synopsis synopsis) + (description description) + (license license)))) + +(define-public tree-sitter-yaml + (tree-sitter-grammar + "yaml" "YAML" + "1bimf5fq85wn8dwlk665w15n2bj37fma5rsfxrph3i9yb0lvzi3q" + "0.5.0" + #:repository-url "https://github.com/ikatyang/tree-sitter-yaml")) -- cgit v1.2.3