Tree-sitter grammar for parsing unified diff files
- Grammar:
grammar.js - Generated parser artifacts:
src/parser.c,src/grammar.json,src/node-types.json - Tree-sitter runtime headers (vendored):
src/tree_sitter/*.h - Corpus tests:
test/corpus/unified_diff.txt - Highlight queries:
queries/highlights.scm - Tree-sitter config:
tree-sitter.json
- Node.js + npm
- Tree-sitter CLI
Install CLI (if needed):
npm install -g tree-sitter-clior use npx without global install:
npx tree-sitter generateInstall dependencies (optional but recommended for script-based usage):
npm installGenerate parser artifacts:
npm run generate
# or: tree-sitter generateRun grammar corpus tests:
npm test
# or: tree-sitter test- preamble lines before file patches
- file headers:
--- <path>+++ <path>
- hunk headers:
@@ -start[,count] +start[,count] @@[ section]
- hunk body lines:
- context (
) - additions (
+) - deletions (
-) - note (
\ No newline at end of file)
- context (
- multiple file patches in one document
This repository is a standard Tree-sitter grammar package. Typical consumption paths:
npm packThen use the packaged grammar from your Tree-sitter binding/tooling environment (Node, Rust, Python, etc.) as configured by tree-sitter.json.
For parser development:
tree-sitter parse path/to/file.diff