GNU bug report logs - #66761
[PATCH] gnu: Add guile-ts.

Previous Next

Package: guix-patches;

Reported by: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>

Date: Thu, 26 Oct 2023 15:06:01 UTC

Severity: normal

Tags: patch

Done: Andrew Tropin <andrew <at> trop.in>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 66761 in the body.
You can then email your comments to 66761 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#66761; Package guix-patches. (Thu, 26 Oct 2023 15:06:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zheng Junjie <zhengjunjie <at> iscas.ac.cn>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Thu, 26 Oct 2023 15:06:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: guix-patches <at> gnu.org
Cc: andrew <at> trop.in
Subject: [PATCH] gnu: Add guile-ts.
Date: Thu, 26 Oct 2023 23:03:19 +0800
* gnu/packages/guile-xyz.scm (guile-ts): New variable.

Change-Id: Icb681b6f2e5f2318291e5a4a4ff05d2cbbcf1856
---
 gnu/packages/guile-xyz.scm | 46 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 90f51cf741..0a2e0a04ae 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -119,6 +119,7 @@ (define-module (gnu packages guile-xyz)
   #:use-module (gnu packages tex)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages tls)
+  #:use-module (gnu packages tree-sitter)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages webkit)
   #:use-module (gnu packages xdisorg)
@@ -4588,6 +4589,51 @@ (define-public guile-torrent
 according to Bitorrent BEP003.")
     (license license:gpl3+)))
 
+(define-public guile-ts
+  (package
+    (name "guile-ts")
+    (version "0.1.0")
+    (source (origin (method git-fetch)
+                    (uri (git-reference
+                          (url
+                           "https://github.com/Z572/guile-ts")
+                          (commit (string-append "v" version))))
+                    (file-name (git-file-name name version))
+                    (sha256
+                     (base32
+                      "0xmq2d3mv921m0g1hqw6bjzh4m622g2c7pal11ks7vjn0m8d4bxj"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list #:make-flags #~(list "GUILE_AUTO_COMPILE=0")
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'set-extension-path
+                 (lambda* (#:key outputs #:allow-other-keys)
+                   (substitute*
+                       (find-files "." ".*\\.scm")
+                     (("\\(load-extension \"libguile_ts\" *\"(.*)\"\\)" _ o)
+                      (string-append
+                       (object->string
+                        `(or (false-if-exception
+                              (load-extension "libguile_ts" ,o))
+                             (load-extension
+                              ,(string-append
+                                #$output
+                                "/lib/libguile_ts.so")
+                              ,o)))))))))))
+    (native-inputs
+     (list autoconf automake
+           libtool
+           texinfo
+           pkg-config
+           guile-3.0))
+    (inputs (list guile-3.0 tree-sitter))
+    (synopsis "Guile bindings to the Tree-sitter parsing library")
+    (description "This package provides Guile bindings to the Tree-sitter
+parsing library.")
+    (home-page "https://github.com/Z572/guile-ts")
+    (license license:gpl3+)))
+
 (define-public guile-irc
   (let ((commit "7d08ce6fdcb87ac668c5d3bfd5584247805507bb")
         (revision "1"))

base-commit: 33f5b747b4a0a508e1ffc94a5bf425cff707c6e3
-- 
2.41.0





Reply sent to Andrew Tropin <andrew <at> trop.in>:
You have taken responsibility. (Fri, 27 Oct 2023 12:26:01 GMT) Full text and rfc822 format available.

Notification sent to Zheng Junjie <zhengjunjie <at> iscas.ac.cn>:
bug acknowledged by developer. (Fri, 27 Oct 2023 12:26:02 GMT) Full text and rfc822 format available.

Message #10 received at 66761-done <at> debbugs.gnu.org (full text, mbox):

From: Andrew Tropin <andrew <at> trop.in>
To: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>, 66761-done <at> debbugs.gnu.org
Subject: Re: [PATCH] gnu: Add guile-ts.
Date: Fri, 27 Oct 2023 16:24:44 +0400
[Message part 1 (text/plain, inline)]
On 2023-10-26 23:03, Zheng Junjie wrote:

> * gnu/packages/guile-xyz.scm (guile-ts): New variable.
>
> Change-Id: Icb681b6f2e5f2318291e5a4a4ff05d2cbbcf1856
> ---
>  gnu/packages/guile-xyz.scm | 46 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
>
> diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
> index 90f51cf741..0a2e0a04ae 100644
> --- a/gnu/packages/guile-xyz.scm
> +++ b/gnu/packages/guile-xyz.scm
> @@ -119,6 +119,7 @@ (define-module (gnu packages guile-xyz)
>    #:use-module (gnu packages tex)
>    #:use-module (gnu packages texinfo)
>    #:use-module (gnu packages tls)
> +  #:use-module (gnu packages tree-sitter)
>    #:use-module (gnu packages version-control)
>    #:use-module (gnu packages webkit)
>    #:use-module (gnu packages xdisorg)
> @@ -4588,6 +4589,51 @@ (define-public guile-torrent
>  according to Bitorrent BEP003.")
>      (license license:gpl3+)))
>  
> +(define-public guile-ts
> +  (package
> +    (name "guile-ts")
> +    (version "0.1.0")
> +    (source (origin (method git-fetch)
> +                    (uri (git-reference
> +                          (url
> +                           "https://github.com/Z572/guile-ts")
> +                          (commit (string-append "v" version))))
> +                    (file-name (git-file-name name version))
> +                    (sha256
> +                     (base32
> +                      "0xmq2d3mv921m0g1hqw6bjzh4m622g2c7pal11ks7vjn0m8d4bxj"))))
> +    (build-system gnu-build-system)
> +    (arguments
> +     (list #:make-flags #~(list "GUILE_AUTO_COMPILE=0")
> +           #:phases
> +           #~(modify-phases %standard-phases
> +               (add-after 'unpack 'set-extension-path
> +                 (lambda* (#:key outputs #:allow-other-keys)
> +                   (substitute*
> +                       (find-files "." ".*\\.scm")
> +                     (("\\(load-extension \"libguile_ts\" *\"(.*)\"\\)" _ o)
> +                      (string-append
> +                       (object->string
> +                        `(or (false-if-exception
> +                              (load-extension "libguile_ts" ,o))
> +                             (load-extension
> +                              ,(string-append
> +                                #$output
> +                                "/lib/libguile_ts.so")
> +                              ,o)))))))))))
> +    (native-inputs
> +     (list autoconf automake
> +           libtool
> +           texinfo
> +           pkg-config
> +           guile-3.0))
> +    (inputs (list guile-3.0 tree-sitter))
> +    (synopsis "Guile bindings to the Tree-sitter parsing library")
> +    (description "This package provides Guile bindings to the Tree-sitter
> +parsing library.")
> +    (home-page "https://github.com/Z572/guile-ts")
> +    (license license:gpl3+)))
> +
>  (define-public guile-irc
>    (let ((commit "7d08ce6fdcb87ac668c5d3bfd5584247805507bb")
>          (revision "1"))
>
> base-commit: 33f5b747b4a0a508e1ffc94a5bf425cff707c6e3

Tested the package with a following snippet of code:

--8<---------------cut here---------------start------------->8---
(use-modules (ts) (oop goops))
(define json-language
  (get-ts-language-from-file
   ;; Can be obtained automatically from TREE_SITTER_GRAMMAR_PATH
   "/gnu/store/537371mad55g34lkmzs3fzp33wh6kidk-profile/lib/tree-sitter/libtree-sitter-json.so"
   "tree_sitter_json"))
(display (ts-language-version json-language))

 (let* ((parser (make <ts-parser> #:language json-language))
        (tree (ts-parser-parse-string parser #f "[1,null, \"hi\"]")))
   (format #t "~s\n" (ts-node-sexp (ts-tree-root-node tree))))
--8<---------------cut here---------------end--------------->8---

guix shell guile guile-ts tree-sitter-json -- guile -s tmp.scm

Added native-search-paths to the package, so if it's installed in the
profile with tree-sitter grammars they are added to respective
environment variable.

--8<---------------cut here---------------start------------->8---
    (native-search-paths
     (list (search-path-specification
            (variable "TREE_SITTER_GRAMMAR_PATH")
            (files '("lib/tree-sitter")))))
--8<---------------cut here---------------end--------------->8---

Thank you for working on tree-sitter bindings, appreciate it very much!

Applied, slightly modified, pushed:
https://git.savannah.gnu.org/cgit/guix.git/commit/?id=fca99c89b8

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 25 Nov 2023 12:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 263 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.