emacs-devel
[Top][All Lists]
Advanced

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

Re: Tree-sitter introduction documentation


From: Gregory Heytings
Subject: Re: Tree-sitter introduction documentation
Date: Fri, 30 Dec 2022 01:01:22 +0000



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.




reply via email to

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