parse command parses source files using a Tree-sitter parser. You can pass any number of file paths and glob patterns, or read from stdin if no paths are provided.
p
The command will exit with a non-zero status code if any parse errors occurred.
Input Sources
File Paths
Pass file paths or glob patterns directly:Paths File
Use--paths to provide a file containing paths:
Standard Input
If no paths are provided, input is read from stdin:Output Formats
Default (S-Expression)
By default, outputs the parse tree as an S-expression:CST Format
Pretty-printed concrete syntax tree:XML Format
Graphviz Dot
JSON Summary
Options
Input Options
file
The path to a file that contains paths to source files to parse.
path
The path to the directory containing the grammar. Implies
--rebuild.path
The path to the parser’s dynamic library. Used instead of the cached or automatically generated library.
string
If
--lib-path is used, the name of the language used to extract the library’s language function.scope
The language scope to use for parsing. Useful when the language is ambiguous.
encoding
Set the encoding of the input file. One of
utf8, utf16-le, utf16-be.By default, the CLI looks for a BOM to determine if the file is UTF-16BE or UTF-16LE. If no BOM is present, UTF-8 is assumed.number
Parse a specific test in the corpus. The test number matches the output of
tree-sitter test.Output Options
flag
Output the parse tree with graphviz dot.
flag
Output the parse tree in XML format.
flag
Output the parse tree in a pretty-printed CST format.
flag
Output parsing results in a JSON format.
flag
Suppress main output.
flag
Omit the node’s ranges from the default parse output. Useful when copying S-Expressions to a test file.
Debug Options
flag | type
Output parsing and lexing logs to stderr. Can optionally specify a debug type.
flag
Output logs of the graphs of the stack and parse trees during parsing. Graphs are constructed with graphviz dot, and output is written to
log.html.flag
When using
--debug-graph, open the log file in the default browser.flag
Compile the parser with debug flags enabled. Useful when debugging with
gdb or lldb.Performance Options
flag
Show parsing statistics.
flag
Print the time taken to parse the file. If edits are provided, also prints time after each edit.
microseconds
Set the timeout for parsing a single file, in microseconds.
Edit Options
edit
Apply edits after parsing the file. Edits are in the format:
row,col|position delcount insert_text where row, col, and position are 0-indexed.Can be supplied multiple times.Build Options
flag
Compile and run the parser as a Wasm module (only if the CLI was built with
--features=wasm).flag
Force a rebuild of the parser before parsing.
path
The path to an alternative configuration (
config.json) file. See init-config.