guix-devel
[Top][All Lists]
Advanced

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

Re: Getting tree-sitter grammars in Guix


From: Demis Balbach
Subject: Re: Getting tree-sitter grammars in Guix
Date: Sat, 04 Feb 2023 20:27:56 +0100

On 2023-01-22 16:38, Simon Tournier wrote:

> Hi,
>
> On Tue, 10 Jan 2023 at 18:29, Demis Balbach <db@minikn.xyz> 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+.
>
> This raises a question about the bootstrap.
>
> From my understanding, the inputs of Tree-sitter is the file
> ’grammar.js’ and then using Node.js, it generates C files.  It is often
> these C files which are considered as the Tree-sitter parser.
>
> Many Tree-sitter parsers are available [1].  For example, Bash [2].  The
> grammar is described by ’grammar.js’ [3] and then using it, the file
> ’src/parser.c’ [4] is generated (note the size 3.46MB!).  Then, using
> this file ’src/parser.c’ is generated a library which is called by the
> editor tool (say Emacs tree-sitter [5]).
>
> I am not aware if someone has tried to rebuild using Guix only from the
> grammar.js to a working tree-sitter editing experience.
>
> Well, considering the state of Node.js and Guix, it appears to me
> difficult to debootstrap.   And maybe, we should accept a large
> unverified seed for Tree-sitter.  Well, I do not know.
>
> What people think?  What do we do with Tree-sitter?
>
>
> 1: <https://tree-sitter.github.io/tree-sitter/>
> 2: <https://github.com/tree-sitter/tree-sitter-bash>
> 3: <https://github.com/tree-sitter/tree-sitter-bash/blob/master/grammar.js>
> 4: <https://github.com/tree-sitter/tree-sitter-bash/blob/master/src/parser.c>
> 5: <https://emacs-tree-sitter.github.io/>
>
>
> Cheers,
> simon

Hello Simon,

Thanks for the input. I came across this:

https://lists.gnu.org/archive/html/guix-devel/2022-12/msg00073.html

Maybe this can be used as a foundation. I tested it locally and it works
fine, but I don't know how it needs to be altered in order to be pushed
upstream.

On that note, how would one package an emacs package that leverages
tree-sitter? I want to package https://github.com/isamert/jsdoc.el which
requires tree-sitter. I wrote a package definition where I substituted

My understanding is that I need to provide emacs with tree-sitter
support as an input for that to work. Here's a package definition I wrote:

--8<---------------cut here---------------start------------->8---
(define-public emacs-jsdoc
  (let ((commit "2e7c02ff2dc422bc21c405bd90a7092c2f599630")
        (revision "0")
        (version "0.2"))
    (package
     (name "emacs-jsdoc")
     (version (git-version version revision commit))
     (source
      (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/isamert/jsdoc.el";)
             (commit commit)))
       (sha256
        (base32 "07sz5lpyqv7ixvnnzdfjkj7f0ykdz31lkljp13pvlf36a6sff4rc"))
       (file-name (git-file-name name version))))
     (build-system emacs-build-system)
     (arguments
      `(#:phases
        (modify-phases
         %standard-phases
         (add-after 'unpack 'patch-bin
                    (lambda* (#:key inputs outputs #:allow-other-keys)
                      (substitute* "jsdoc.el"
                                   (("'tree-sitter") "'treesit")))))))
     (inputs
      (list
       ;; tree-sitter
       emacs-next-pgtk-stable
       emacs-s
       emacs-dash))
     (home-page "https://github.com/isamert/jsdoc.el";)
     (synopsis "Inserts JSDoc function comments/typedefs easily.")
     (description "Inserts JSDoc function comments/typedefs easily.
It also tries to infer types by itself while doing that.
Type inference is quite primitive.")
     (license license:gpl3+))))     
--8<---------------cut here---------------end--------------->8---

My understanding is that I need to provide emacs with tree-sitter
support as an input for this to work, which I did, but it'll fail with

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (file-missing "Cannot open load file" "No such 
file or directory" "treesit")
--8<---------------cut here---------------end--------------->8---

Maybe someone can help me here. I tried looking at other package
definitions, but I don't know if there are any emacs packages that
require tree-sitter packaged in Guix yet.

Thanks in advance.

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

Attachment: signature.asc
Description: PGP signature


reply via email to

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