summary refs log tree commit diff
path: root/gnu/packages/tree-sitter.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/packages/tree-sitter.scm')
-rw-r--r--gnu/packages/tree-sitter.scm76
1 files changed, 76 insertions, 0 deletions
diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm
index 8951c2ff57..f7e35a062c 100644
--- a/gnu/packages/tree-sitter.scm
+++ b/gnu/packages/tree-sitter.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2022 muradm <mail@muradm.net>
 ;;; Copyright © 2022 Aleksandr Vityazev <avityazev@posteo.org>
 ;;; Copyright © 2023 Andrew Tropin <andrew@trop.in>
+;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,6 +23,7 @@
 
 (define-module (gnu packages tree-sitter)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages)
   #:use-module (gnu packages crates-graphics)
   #:use-module (gnu packages crates-io)
   #:use-module (gnu packages graphviz)
@@ -29,12 +31,68 @@
   #:use-module (gnu packages node)
   #:use-module (guix build-system cargo)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system pyproject)
   #:use-module (guix build-system tree-sitter)
   #:use-module (guix gexp)
   #:use-module (guix git-download)
   #:use-module (guix packages)
   #:use-module (guix utils))
 
+(define-public python-tree-sitter
+  (package
+    (name "python-tree-sitter")
+    (version "0.20.1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/tree-sitter/py-tree-sitter")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "1rc8zqiry4n52xlf7pwx4s56ka9vwjzwgn7blwbkiscqdwvsai92"))))
+    (build-system pyproject-build-system)
+    (arguments
+     (list
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'set-tree-sitter-lib-path
+            (lambda _
+              (let ((tree-sitter #$(this-package-input "tree-sitter")))
+                (substitute* "setup.py"
+                  (((string-append
+                     "( *)\\[\"tree_sitter\\/core\\/lib\\/src\\/lib\\.c\", "
+                     "\"tree_sitter\\/binding\\.c\"\\],") all tabs)
+                   (string-append
+                    tabs "[\"tree_sitter/binding.c\"],\n"
+                    tabs "library_dirs=[\"" tree-sitter "/lib\"],\n"
+                    tabs "libraries=[\"tree-sitter\"],"))
+                  (("include_dirs=.*")
+                   (string-append
+                    "include_dirs=[\"" tree-sitter "/include\"],\n"))))))
+          (add-before 'check 'set-test-lib-paths
+            (lambda _
+              (let ((py #$(this-package-native-input "tree-sitter-python"))
+                    (js #$(this-package-native-input "tree-sitter-javascript")))
+                (substitute* "tests/test_tree_sitter.py"
+                  (("Language\\.build_library")
+                   "_ =")
+                  (("LIB_PATH(, \"python\")" all name)
+                   (string-append
+                    "\"" py "/lib/tree-sitter/libtree-sitter-python.so\"" name))
+                  (("LIB_PATH(, \"javascript\")" all name)
+                   (string-append
+                    "\"" js "/lib/tree-sitter/libtree-sitter-javascript.so\""
+                    name)))))))))
+    (inputs (list tree-sitter))
+    (native-inputs
+     (list tree-sitter-python tree-sitter-javascript))
+    (home-page "https://github.com/tree-sitter/py-tree-sitter")
+    (synopsis "Python bindings to the Tree-sitter parsing library")
+    (description "This package provides Python bindings to the
+Tree-sitter parsing library.")
+    (license license:expat)))
+
 (define-public tree-sitter
   (package
     (name "tree-sitter")
@@ -266,6 +324,17 @@ will be used in description and synopsis."
    #:inputs (list tree-sitter-javascript)
    #:grammar-directories '("typescript" "tsx")))
 
+(define-public tree-sitter-bibtex
+  (let ((commit "ccfd77db0ed799b6c22c214fe9d2937f47bc8b34")
+        (revision "0"))
+    (tree-sitter-grammar
+     "bibtex" "Bibtex"
+     "0m7f3dkqbmy8x1bhl11m8f4p6n76wfvh99rp46zrqv39355nw1y2"
+     (git-version "0.1.0" revision commit)
+     #:repository-url "https://github.com/latex-lsp/tree-sitter-bibtex"
+     #:commit commit
+     #:license license:expat)))
+
 (define-public tree-sitter-css
   (tree-sitter-grammar
    "css" "CSS"
@@ -329,6 +398,13 @@ will be used in description and synopsis."
    #:article "an"
    #:repository-url "https://github.com/elm-tooling/tree-sitter-elm"))
 
+(define-public tree-sitter-gomod
+  (tree-sitter-grammar
+   "gomod" "Go .mod"
+   "1hblbi2bs4hlil703myqhvvq2y1x41rc3w903hg2bhbazh7x8yyf"
+   "1.0.0"
+   #:repository-url "https://github.com/camdencheek/tree-sitter-go-mod.git"))
+
 (define-public tree-sitter-go
   ;; There are a lot of additions, the last tag was placed more than 1 year ago
   (let ((commit "64457ea6b73ef5422ed1687178d4545c3e91334a")