[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: Fri, 30 Dec 2022 11:00:48 +0000

Gregory Heytings <gregory@heytings.org> writes:

>> 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,
>> which is easier to build
> You asked for it, so here it is:
> global = {}
> module = {}
> process = { env: { TREE_SITTER_GRAMMAR_PATH: './grammar.js' } }
> function require(s) { std.loadScript(s); return module.exports; }
> std.loadScript('/path/to/the/script/dsl.js')
> Put these five lines in a file, say "gen.js", cd in the directory of a
> tree-sitter-<lang> repository, and type
> qjs --std /path/to/the/script/gen.js > src/grammar.json
> For simple grammars (bash, c, cmake, csharp, css, dockerfile, go,
> go-mod, java, js, json, python, rust, yaml), this will work out of the
> box.  For more complex ones (c++, toml, tsx, typescript), you'll need
> to edit the grammar.js file.  That is left as an exercise for the
> reader.
> Disclaimer: this is NOT what I recommend anyone to do!  TRT is to
> install and use Node.js, at least if you want to spare yourself
> headaches.

I should have clarified this further up in the thread, but I did try
this out and confirmed that it does work (or at least I hope I did say
that).  I didn't have a nice script like you give here, but that this is
possible was clear.

reply via email to

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