[Top][All Lists]

[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: Thu, 29 Dec 2022 15:45:28 +0000

Gregory Heytings <gregory@heytings.org> writes:

>> Do you know how strong the dependency on node is?  As I said before,
>> it seems that it is possible to evaluate the grammar files that use
>> the DSL using something like quickjs as well
> That's not possible, no, at least not without a lot of complications
> that do not seem worth the price, compared to installing Node.js.  And
> note that even if that were feasible, it would only solve the first
> half of the problem: to transform a grammar.js file into its
> corresponding parser.c file, you also need the tree-sitter command
> line program.

Not necessarily, that could also be ported to JavaScript.  That being
said, I don't imagine it to be an easy process.  I am probably
underestimating how much of the code is shared in a library and how much
is generated.

>> but it appears that it should be possible for them to also load
>> arbitrary node.js libraries as well
> Indeed, grammar authors are not limited to the standard Node.js API,
> they can import other libraries.  For example, tree-sitter-toml
> requires the regexp-util library.

How common is this in practice?  Is it encouraged?  The example you cite
would be trivial to fix:

--8<---------------cut here---------------start------------->8---
const { Charset } = require("regexp-util");

const getInverseRegex = charset =>
  new RegExp(`[^${charset.toString().slice(1, -1)}]`);

const control_chars = new Charset([0x0, 0x1f], 0x7f);
--8<---------------cut here---------------end--------------->8---

Just replace the "new Charset([0x0, 0x1f], 0x7f)" with the result of
evaluating the expression.

reply via email to

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