Subject: bug#61849: 29.0.60; Unable to use treesit-install-language-grammar because repo doesn't have parser.c

From: Gregory Heytings <[email-masked]>
Date: Tue, 21 Mar 2023 09:39:31 +0000

>> Generating the grammar.json files from the grammar.js files with an 
>> Emacs Lisp program would amount to implement a JavaScript interpreter 
>> in Emacs Lisp.
>
> So you are saying that generating a parser would need a JavaScript 
> interpreter as part of the generation?
>

Yes.

>
> Does tree-sitter-cli tool invoke it, then (I didn't study its sources)?
>

Yes, here: https://github.com/tree-sitter/tree-sitter/blob/master/cli/src/generate/mod.rs#L169.

>> And generating the parser.c files from the grammar.json files would 
>> amount to reimplement the generator, which is about 13500 lines of 
>> non-trivial Rust code, in Emacs Lisp.
>
> That's what I hoped someone will do, yes.  It's a non-trivial job, but 
> surely isn't impossible.  Reimplementing that in some other widely 
> available language, like Python or Perl, would also do.  Or maybe the 
> Rust front-end to GCC will become available soon enough.  Or something.
>

It's not impossible, but what would be the benefit (and/or incentive) of 
doing that?  Rust is already widely available, under a liberal licence, 
and it is also not necessary to create the parser.c file, which is 
architecture-independent, on the computer on which it is compiled.  Also 
note that generating the parser.c file can use _a lot_ of resources, e.g. 
generating the parser.c file of tree-sitter-c-sharp from the grammar.json 
file uses 40 (fourty!) GB of memory and takes several minutes.  I'll let 
you imagine what these numbers would be with an interpreted language like 
Elisp, Python or Perl.