unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Getting tree-sitter grammars in Guix
@ 2023-01-10 17:29 Demis Balbach
  2023-01-21 16:43 ` Katherine Cox-Buday
  0 siblings, 1 reply; 3+ messages in thread
From: Demis Balbach @ 2023-01-10 17:29 UTC (permalink / raw)
  To: help-guix; +Cc: andrew

[-- Attachment #1: Type: text/plain, Size: 3202 bytes --]


Hello, I was wondering what the "correct" way would be to get grammars
for the tree-sitter library available in Guix when using tree-sitter
with Emacs 29+.

There is https://github.com/emacs-tree-sitter/tree-sitter-langs, but I
don't think it has been packaged in Guix yet. I started packaging the
grammar for JS/TS:

--8<---------------cut here---------------start------------->8---
(define-public tree-sitter-javascript
  (let ((commit "7a29d06274b7cf87d643212a433d970b73969016")
        (revision "0")
        (version "0.20.0"))
    (package
     (name "tree-sitter-javascript")
     (version (git-version version revision commit))
     (source
      (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/tree-sitter/tree-sitter-javascript")
             (commit commit)))
       (sha256
        (base32 "1pk6d9g6a7bzhxmwnvfiycarcgz76wq2rgfqr0xjh7y7swfw5hvw"))
       (file-name (git-file-name name version))))
     (build-system gnu-build-system)
     (native-inputs
      (list gcc))
     (arguments
      `(#:tests?
        #f
        #:phases
        (modify-phases
         %standard-phases
         (delete 'configure)
         (delete 'install)
         (delete 'build)
         (add-after 'unpack 'create-dirs
                    (lambda _ (mkdir "lib")))
         (add-after 'create-dirs 'compile
                    (lambda* (#:key inputs outputs #:allow-other-keys)
                      (let* ((out (assoc-ref outputs "out"))
                             (gcc (string-append (assoc-ref inputs "gcc") "/bin")))
                        (copy-file "grammar.js" "src/grammar.js")
                        (with-directory-excursion
                         (string-append "./src")
                         (invoke (string-append gcc "/gcc") "-fPIC" "-c" "-I." "parser.c")
                         (invoke (string-append gcc "/gcc") "-fPIC" "-c" "-I." "scanner.c")
                         (invoke (string-append gcc "/gcc")
                                 "-fPIC" "-shared" "parser.o" "scanner.o" "-o"
                                 "libtree-sitter-javascript.so")))))
         (add-after 'compile 'symlink
                    (lambda* (#:key inputs outputs #:allow-other-keys)
                      (let* ((out (assoc-ref outputs "out"))
                             (lib (string-append out "/lib")))
                        (install-file "src/libtree-sitter-javascript.so" lib)))))))
      (home-page "https://github.com/tree-sitter/tree-sitter-javascript")
     (synopsis "JavaScript and JSX grammar for tree-sitter.")
     (description "JavaScript and JSX grammar for tree-sitter.")
     (license license:expat))))
--8<---------------cut here---------------end--------------->8---

But I'm not sure if packaging each grammar is the correct way. I
hesitate to continue working on this because there are not other
grammars packaged in Guix (yet). With tree-sitter being built into Emacs
29+ I expected grammars to be packaged already (hence why I'm asking if
this approach is correct).

Thanks in advance!

-- 
Best regards / Mit freundlichen Grüßen,
Demis Balbach

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Getting tree-sitter grammars in Guix
  2023-01-10 17:29 Demis Balbach
@ 2023-01-21 16:43 ` Katherine Cox-Buday
  0 siblings, 0 replies; 3+ messages in thread
From: Katherine Cox-Buday @ 2023-01-21 16:43 UTC (permalink / raw)
  To: Demis Balbach; +Cc: help-guix, andrew, Guix Devel

Demis Balbach <db@minikn.xyz> writes:

> Hello, I was wondering what the "correct" way would be to get grammars
> for the tree-sitter library available in Guix when using tree-sitter
> with Emacs 29+.
>
> There is https://github.com/emacs-tree-sitter/tree-sitter-langs, but I
> don't think it has been packaged in Guix yet. I started packaging the
> grammar for JS/TS:
>
> (define-public tree-sitter-javascript
>   (let ((commit "7a29d06274b7cf87d643212a433d970b73969016")
>         (revision "0")
>         (version "0.20.0"))
>     (package
>      (name "tree-sitter-javascript")
>      (version (git-version version revision commit))
>      (source
>       (origin
>        (method git-fetch)
>        (uri (git-reference
>              (url "https://github.com/tree-sitter/tree-sitter-javascript")
>              (commit commit)))
>        (sha256
>         (base32 "1pk6d9g6a7bzhxmwnvfiycarcgz76wq2rgfqr0xjh7y7swfw5hvw"))
>        (file-name (git-file-name name version))))
>      (build-system gnu-build-system)
>      (native-inputs
>       (list gcc))
>      (arguments
>       `(#:tests?
>         #f
>         #:phases
>         (modify-phases
>          %standard-phases
>          (delete 'configure)
>          (delete 'install)
>          (delete 'build)
>          (add-after 'unpack 'create-dirs
>                     (lambda _ (mkdir "lib")))
>          (add-after 'create-dirs 'compile
>                     (lambda* (#:key inputs outputs #:allow-other-keys)
>                       (let* ((out (assoc-ref outputs "out"))
>                              (gcc (string-append (assoc-ref inputs "gcc") "/bin")))
>                         (copy-file "grammar.js" "src/grammar.js")
>                         (with-directory-excursion
>                          (string-append "./src")
>                          (invoke (string-append gcc "/gcc") "-fPIC" "-c" "-I." "parser.c")
>                          (invoke (string-append gcc "/gcc") "-fPIC" "-c" "-I." "scanner.c")
>                          (invoke (string-append gcc "/gcc")
>                                  "-fPIC" "-shared" "parser.o" "scanner.o" "-o"
>                                  "libtree-sitter-javascript.so")))))
>          (add-after 'compile 'symlink
>                     (lambda* (#:key inputs outputs #:allow-other-keys)
>                       (let* ((out (assoc-ref outputs "out"))
>                              (lib (string-append out "/lib")))
>                         (install-file "src/libtree-sitter-javascript.so" lib)))))))
>       (home-page "https://github.com/tree-sitter/tree-sitter-javascript")
>      (synopsis "JavaScript and JSX grammar for tree-sitter.")
>      (description "JavaScript and JSX grammar for tree-sitter.")
>      (license license:expat))))
>
> But I'm not sure if packaging each grammar is the correct way. I
> hesitate to continue working on this because there are not other
> grammars packaged in Guix (yet). With tree-sitter being built into
> Emacs 29+ I expected grammars to be packaged already (hence why I'm
> asking if this approach is correct).


This seems correct to me, but you might get more informed opinions on
guix-devel@gnu.org (CCed), since this is a packaging question.

>
> Thanks in advance!

-- 
Katherine


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Getting tree-sitter grammars in Guix
@ 2023-02-04  4:52 Andrew Tropin
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Tropin @ 2023-02-04  4:52 UTC (permalink / raw)
  To: Demis Balbach, help-guix

[-- Attachment #1: Type: text/plain, Size: 3986 bytes --]

On 2023-01-10 18:29, Demis Balbach wrote:

> Hello, I was wondering what the "correct" way would be to get grammars
> for the tree-sitter library available in Guix when using tree-sitter
> with Emacs 29+.
>
> There is https://github.com/emacs-tree-sitter/tree-sitter-langs, but I
> don't think it has been packaged in Guix yet. I started packaging the
> grammar for JS/TS:
>
> --8<---------------cut here---------------start------------->8---
> (define-public tree-sitter-javascript
>   (let ((commit "7a29d06274b7cf87d643212a433d970b73969016")
>         (revision "0")
>         (version "0.20.0"))
>     (package
>      (name "tree-sitter-javascript")
>      (version (git-version version revision commit))
>      (source
>       (origin
>        (method git-fetch)
>        (uri (git-reference
>              (url "https://github.com/tree-sitter/tree-sitter-javascript")
>              (commit commit)))
>        (sha256
>         (base32 "1pk6d9g6a7bzhxmwnvfiycarcgz76wq2rgfqr0xjh7y7swfw5hvw"))
>        (file-name (git-file-name name version))))
>      (build-system gnu-build-system)
>      (native-inputs
>       (list gcc))
>      (arguments
>       `(#:tests?
>         #f
>         #:phases
>         (modify-phases
>          %standard-phases
>          (delete 'configure)
>          (delete 'install)
>          (delete 'build)
>          (add-after 'unpack 'create-dirs
>                     (lambda _ (mkdir "lib")))
>          (add-after 'create-dirs 'compile
>                     (lambda* (#:key inputs outputs #:allow-other-keys)
>                       (let* ((out (assoc-ref outputs "out"))
>                              (gcc (string-append (assoc-ref inputs "gcc") "/bin")))
>                         (copy-file "grammar.js" "src/grammar.js")
>                         (with-directory-excursion
>                          (string-append "./src")
>                          (invoke (string-append gcc "/gcc") "-fPIC" "-c" "-I." "parser.c")
>                          (invoke (string-append gcc "/gcc") "-fPIC" "-c" "-I." "scanner.c")
>                          (invoke (string-append gcc "/gcc")
>                                  "-fPIC" "-shared" "parser.o" "scanner.o" "-o"
>                                  "libtree-sitter-javascript.so")))))
>          (add-after 'compile 'symlink
>                     (lambda* (#:key inputs outputs #:allow-other-keys)
>                       (let* ((out (assoc-ref outputs "out"))
>                              (lib (string-append out "/lib")))
>                         (install-file "src/libtree-sitter-javascript.so" lib)))))))
>       (home-page "https://github.com/tree-sitter/tree-sitter-javascript")
>      (synopsis "JavaScript and JSX grammar for tree-sitter.")
>      (description "JavaScript and JSX grammar for tree-sitter.")
>      (license license:expat))))
> --8<---------------cut here---------------end--------------->8---
>
> But I'm not sure if packaging each grammar is the correct way. I
> hesitate to continue working on this because there are not other
> grammars packaged in Guix (yet). With tree-sitter being built into Emacs
> 29+ I expected grammars to be packaged already (hence why I'm asking if
> this approach is correct).
>
> Thanks in advance!

Hi Demis!

We have some work for tree-sitter done by muradm and he made an example
of the function, which returns a package for a tree-sitter grammar for
particular language, I think that we want to do something like this:
https://yhetil.org/guix-devel/87sfhvm927.fsf@encom.net/3-a.txt

Thank you very much for your snippet, I'll experiment a little more with
tree-sitter locally and report back with more details.

Also, I applied a patch, which enables built-in treesitter in Emacs
from this thread:
https://yhetil.org/guix-patches/87a6217tw5.fsf@riseup.net/

So I hope we will get tree-sitter support in Guix soon!

-- 
Best regards,
Andrew Tropin

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-04  4:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-04  4:52 Getting tree-sitter grammars in Guix Andrew Tropin
  -- strict thread matches above, loose matches on Subject: below --
2023-01-10 17:29 Demis Balbach
2023-01-21 16:43 ` Katherine Cox-Buday

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).