你如何打包一个 tree-sitter 语法以供使用?

How do you package a tree-sitter grammar for consumption?

假设您想编写一个程序来使用您编写的 tree-sitter 语法,使用 node-tree-sitter package. How do you package the grammar you've written for consumption? What is the minimal set of files that must be included in the node module? In the package.json file of the javascript module 有一个特定于 tree-sitter 的部分,填写它很重要吗?

不,package.json 的那部分仅在 运行 tree-sitter parsetree-sitter highlight 时由 tree-sitter CLI 工具使用。它被描述为 here.

要在 node-tree-sitter 中使用 Tree-sitter 语法,您只需确保 nan 模块包含在 package.json 的 dependencies 中。 tree-sitter generate 命令将生成将代码公开给 Node.js 所需的其他文件:binding.gypsrc/binding.cc。如果您想将模块发布到 npmjs.com,您可以使用 usual commands(例如 npm publish)。