guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

07/07: gnu: Add tree-sitter-grammar-html.


From: guix-commits
Subject: 07/07: gnu: Add tree-sitter-grammar-html.
Date: Thu, 9 Feb 2023 08:38:55 -0500 (EST)

abcdw pushed a commit to branch master
in repository guix.

commit 53b00b91b73bd60412d5bd057e22e6d63194a7f7
Author: Andrew Tropin <andrew@trop.in>
AuthorDate: Thu Feb 9 17:34:05 2023 +0400

    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 <luishenriquegh2701@gmail.com>
 ;;; Copyright © 2022 Pierre Langlois <pierre.langlois@gmx.com>
+;;; Copyright © 2022 muradm <mail@muradm.net>
+;;; Copyright © 2022 Aleksandr Vityazev <avityazev@posteo.org>
+;;; Copyright © 2023 Andrew Tropin <andrew@trop.in>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -151,3 +154,61 @@ can be embedded in any application.
 
 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"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]