Closed mikavilpas closed 8 months ago
You can't extend the grammar.json
; you need to extend grammar.js
(using node) directly. Look at how the cpp parser derives from c, or how the various shader languages derive from cpp.
Ok, thanks for the tip. Do you know what the purpose of grammar.json
is, then?
I checked and it seems like the cpp parser project exports it, too.
https://www.npmjs.com/package/tree-sitter-cpp?activeTab=code
(src/grammar.json
)
Yes, it's a compact, machine-readable, representation of the grammar that tooling can use. For example, you can regenerate or build the parser from it via tree-sitter generate grammar.json
(which is important in your case since you don't need to access the base grammar, which generating from grammar.js
needs to import).
In general, we are in the process of unifying the tooling (documentation, workflows, bindings, manifests) of all the grammars in this org based on improved upstream support; we just haven't gotten to this one yet. So I would ask you to wait with any such improvements that are likely to be overridden anyway.
Fixed in 5520eaa328d41f6817b86c1da7b4d87c705a64a8 & 62516e8c78380e3b51d5b55727995d2c511436d8
Include the grammar files in the npm package
I started to work on a parser for a markdown derived language used by presenterm. I am new to tree-sitter parser development, but I think what I want to do is reuse the grammar from this parser and essentially add a couple of things on top.
Currently, the grammar is not included in the npm package, so I can't extend it. I think this is because the
files
field in thepackage.json
file does not include the grammar files.The current contents of the package can be seen here:
https://www.npmjs.com/package/@tree-sitter-grammars/tree-sitter-markdown/v/0.2.1?activeTab=code
The fix
To fix this, I added the grammar files to the
files
field in thepackage.json
file.npm publish before the changes:
npm publish after the changes: