emacs-devel
[Top][All Lists]
Advanced

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

Re: Tree-sitter introduction documentation


From: Philip Kaludercic
Subject: Re: Tree-sitter introduction documentation
Date: Tue, 27 Dec 2022 20:06:05 +0000

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Eli Zaretskii [2022-12-27 20:08:32] wrote:
>> Good luck with that!  It requires to install Node.js and other stiff,
>> which I personally won't touch with a 3-mile pole, and I'm unsure (but
>> never bothered to find out) whether free replacements even exist.
>
> That's the part of Tree-sitter which makes me a bit uneasy.

I took a look at an the C grammar, and it doesn't appear to use any
fancy Javascript stuff:

  
https://github.com/tree-sitter/tree-sitter-c/blob/0720f9c2af2a97dcd0e9ed90324d1baba68b2849/grammar.js

Depending on who or what loads these files, it might be possible to use
something nice like quickjs (https://bellard.org/quickjs/) to generate
the intermediate C files.

The documentation at

  https://tree-sitter.github.io/tree-sitter/creating-parsers

indicates that the tree-sitter toolchain is written in Rust (yet another
build-time dependency), but unless I am mistaken, it just invokes "node"

  
https://github.com/tree-sitter/tree-sitter/blob/9866674cf87fcd1cd7e424eecdbf260f8947a784/cli/src/generate/mod.rs#L169

and pipes this file

  https://github.com/tree-sitter/tree-sitter/blob/master/cli/src/generate/dsl.js

into the process.  The output of this script is JSON, and it seems like
pretty vanilla Javascript.  If I manage to build QuickJS, I'll try and
see if this can be used to process a grammar.

The remaining part that generates the C code is written in Rust, and
translates the JSON output into C:

  
https://github.com/tree-sitter/tree-sitter/blob/9866674cf87fcd1cd7e424eecdbf260f8947a784/cli/src/generate/mod.rs#L116

and

  
https://github.com/tree-sitter/tree-sitter/blob/9866674cf87fcd1cd7e424eecdbf260f8947a784/cli/src/generate/render.rs#L95

It should be possible to port this, but I question if it is worth the
effort.  As Stefan said, it really looks like something that
distributions should take care of -- though considering that Emacs isn't
the first editor with TreeSitter support, I wonder why this hasn't
happened yet. 



reply via email to

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