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 15:23:27 +0000


The script I sent is meant to clarify that point: to show how and to what extent it is possible, and what the complications (having to modify the source grammars manually) are.

You are right, sorry about that.


No worries.

I extended the hack a bit further:

global = {}
module = {}
process = { env: { TREE_SITTER_GRAMMAR_PATH: 'grammar.js' } }
function require(file) {
  const pref = [ "", "./", "../", "../../", "../../../" ];
  const suff = [ "", ".js" ];
  for (let i in pref)
    for (let j in suff) {
      const f = pref[i] + file + suff[j];
      if (std.open(f, "r") !== null) {
        os.chdir(f.match(/.*\//));
        eval(std.loadFile(f.replace(/.*\//, '')));
        return module.exports;
      }
    }
  throw Error('File ' + file + ' not found');
}
std.loadScript('/path/to/the/script/dsl.js')

With that script, if you clone the 63 repositories listed on https://tree-sitter.github.io/tree-sitter/, and the tree-sitter-clojure repository (which is used by tree-sitter-commonlisp), in the same directory, you can generate 64 out of the 66 grammar.json files (two repositories contain two grammars: tree-sitter-typescript and tree-sitter-wasm) without any modification with:

qjs --std /path/to/that/script.js > src/grammar.json

The two exceptions are swift (in the the grammar.json file produced by qjs, two values seem to be misplaced) and toml (because it depends on regexp-util).




reply via email to

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