The most important command for grammar development. It reads the grammar and outputs C files that can be compiled into a shared or static library.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
gen, g
Grammar Path
The optionalGRAMMAR_PATH argument should point to the structured grammar in one of two forms:
grammar.js- A JavaScript file (ESM or CJS). If omitted, defaults to./grammar.js.grammar.json- A structured representation created as a byproduct ofgenerate. Can regenerate a missingparser.cwithout requiring a JavaScript runtime.
Conflict Detection
If there is an ambiguity or local ambiguity in your grammar, Tree-sitter will detect it during parser generation and exit with anUnresolved conflict error message.
See Structuring Rules Well for information on handling conflicts.
Generated Files
src/parser.c
Implements the parser logic specified in the grammar.src/tree_sitter/parser.h
Provides basic C definitions used in the generatedparser.c file.
src/tree_sitter/alloc.h
Provides memory allocation macros that can be used in an external scanner.src/tree_sitter/array.h
Provides array macros that can be used in an external scanner.src/grammar.json
Contains a structured representation of the grammar. Can regenerate the parser without re-evaluatinggrammar.js.
src/node-types.json
Provides type information about individual syntax nodes. See Static Node Types.Options
Print the log of the parser generation process. Includes information about tokens in error recovery state, extracted keywords, state splits, and entry point state.
The ABI version to use for parser generation. Default is ABI 15, with ABI 14 being a supported target. Use
latest to generate the newest supported version.Can also be set via TREE_SITTER_ABI_VERSION environment variable.Only generate
grammar.json and node-types.json without generating the parser.The directory to place the generated parser in. Default is
src/ in the current directory.Print the overview of states from the given rule. Useful for debugging and understanding the generated parser’s item sets.
- Pass
-to view state count numbers for all rules - Pass
*to view the overview of states for every rule
Report conflicts in a JSON format.
Path to the JavaScript runtime executable to use when generating the parser.Can also be set via
TREE_SITTER_JS_RUNTIME environment variable.Starting from version 0.26, you can pass native to use the experimental native QuickJS runtime bundled with the CLI. This avoids the Node.js dependency entirely.The native QuickJS runtime is compatible with ESM and CommonJS in strict mode. If your grammar depends on npm packages, run npm install before using the native runtime.Disable optimizations when generating the parser. Currently only affects the merging of compatible parse states.