From 53b00b91b73bd60412d5bd057e22e6d63194a7f7 Mon Sep 17 00:00:00 2001 From: Andrew Tropin Date: Thu, 9 Feb 2023 17:34:05 +0400 Subject: [PATCH] gnu: Add tree-sitter-grammar-html. * gnu/packages/crates-io.scm (tree-sitter-grammar): New variable. (tree-sitter-grammar-html): New variable. --- gnu/packages/tree-sitter.scm | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm index 4a5e082e5b..2e44339ca2 100644 --- a/gnu/packages/tree-sitter.scm +++ b/gnu/packages/tree-sitter.scm @@ -1,6 +1,9 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2022 Luis Henrique Gomes Higino ;;; Copyright © 2022 Pierre Langlois +;;; Copyright © 2022 muradm +;;; Copyright © 2022 Aleksandr Vityazev +;;; Copyright © 2023 Andrew Tropin ;;; ;;; This file is part of GNU Guix. ;;; @@ -151,3 +154,61 @@ (define-public tree-sitter-cli This package includes the @command{tree-sitter} command-line tool.") (license license:expat))) + +(define* (tree-sitter-grammar + language language-for-synopsis version commit hash + #:key + (repository-url + (format #f "https://github.com/tree-sitter/tree-sitter-~a" language)) + (source-directory "")) + (let ((synopsis (string-append language-for-synopsis + " grammar for tree-sitter")) + (name (string-append "tree-sitter-grammar-" language)) + (src-dir source-directory) + (lib (format #f "libtree-sitter-~a.so" language))) + (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)))) + (build-system gnu-build-system) + (arguments + (list + #:phases + #~(modify-phases %standard-phases + (delete 'configure) + (replace 'build + (lambda _ + (with-directory-excursion (string-append #$src-dir "src") + (let* ((scanner? (or (file-exists? "scanner.c") + (file-exists? "scanner.cc"))) + (CC (if (file-exists? "scanner.cc") "g++" "gcc")) + (compile (lambda (f) (invoke CC "-fPIC" "-c" "-I." f))) + (link-args `("-fPIC" "-shared" "parser.o" + ,@(if scanner? '("scanner.o") '()) + "-o" ,#$lib))) + (invoke "gcc" "-fPIC" "-c" "-I." "parser.c") + (for-each + (lambda (f) (when (file-exists? f) (compile f))) + '("scanner.c" "scanner.cc")) + (apply invoke CC link-args))))) + (delete 'check) + (replace 'install + (lambda _ + (install-file (string-append #$src-dir "src/" #$lib) + (string-append #$output "/lib/tree-sitter"))))))) + (synopsis synopsis) + (description (string-append synopsis ".")) + (license license:expat)))) + +(define-public tree-sitter-grammar-html + (tree-sitter-grammar + "html" "HTML" + "0.19.0" "v0.19.0" + "1hg7vbcy7bir6b8x11v0a4x0glvqnsqc3i2ixiarbxmycbgl3axy"))