Based on the documentation, if I'm not mistaken, the only way to use the parser is via C, but my current language development uses Javascript to do code generation. So, I'm wondering if it is possible to output the syntax tree generated by parser(generated using tree-sitter) into JSON? Because I'm considering to switch from jison to tree-sitter after watching this video.
I just found the answer at https://github.com/tree-sitter/node-tree-sitter.
Yeah, sorry the docs are a work in progress. Glad you found it!
@maxbrunsfeld I have one problem, how do I know what is the name for the language? For example, I tried to generate the grammer for this arithmetic language (based on the README.md of tree-sitter-cli).
Then I have this binding.gyp file, but how do I import it in to Javascript file? The example given here is
const Parser = require('tree-sitter');
const JS = require('tree-sitter-javascript'); // <--- How do I know what name to use??
const parser = new Parser();
parser.setLanguage(JS);
I read from here that the filename comes from tree_sitter_${LANGUAGE_NAME}, but where does ${LANGUAGE_NAME} comes from?
Because I tried to do require('tree-sitter-arithmetic') but it does not work. (Maybe I miss step to build the parser. In fact I did, I miss out the step to node-gyp build the binding.gyp)
@maxbrunsfeld No worries, I would try to help out if I figured out how to use the parser in Javascript.
Finally I found out how to do it. Will close this once I created a PR for the documentation.
Ok, the section of the docs about using the parsers now links to node-tree-sitter explicitly. I'm going to close this one out. Thanks for pointing out some missing pieces on this.
Most helpful comment
Ok, the section of the docs about using the parsers now links to
node-tree-sitterexplicitly. I'm going to close this one out. Thanks for pointing out some missing pieces on this.