Adding a New Parser
This guide walks you through adding a new language parser to nvim-treesitter.Parser Requirements
Tier 1 vs Tier 2
Tier 1 parsers (preferred) additionally need to:- Make regular releases following semver:
- Patch for fixes not affecting queries
- Minor for changes introducing new nodes or patterns
- Major for changes removing nodes or previously valid patterns
- Provide WASM release artifacts
Adding the Parser
Edit lua/nvim-treesitter/parsers.lua
Add an entry to the returned table with your language configuration:
Register filetype mapping (if needed)
If the parser name differs from the Vim filetype, add an entry to the
filetypes table in plugin/filetypes.lua:Add queries
Create query files in
runtime/queries/zimbu/:highlights.scm- Required for syntax highlightinginjections.scm- For multi-language support (optional)folds.scm- For code folding (optional)indents.scm- For automatic indentation (optional)
Update documentation
Run the documentation generator to update the supported languages list:Or on Windows:
Using Local Paths
For local parser development, you can use apath instead of url:
Local paths always use the directory’s current state. The
branch and revision fields are ignored.Submitting Your PR
When you’re ready, open a Pull Request using the provided template:PR Checklist
Before submitting, ensure:./scripts/install-parsers.lua <language>works without warnings./scripts/install-parsers.lua --generate <language>works without warningsmake queryworks without warningsmake docshas been run- You’ve added at least a
highlights.scmquery file
PR Content
Your PR should include:- Language name and description - Link to official language documentation
- File extension - E.g.,
.zu - Representative code sample - Max 50 lines showing typical language features
- Parser repository - GitHub URL
- Parsed tree - Output from
tree-sitter parseor:InspectTree - Query source - Where the queries came from or “written from scratch”
- Screenshots - Code sample with syntax highlighting applied
Parser Configuration Options
Required Fields
install_info.urlorinstall_info.path- Parser locationinstall_info.revision- Tag or commit hash (not needed for local paths)maintainers- Array of GitHub usernames who maintain the queriestier- 1 for versioned releases, 2 for latest commit
Optional Fields
install_info.branch- Use a non-default branchinstall_info.location- Subdirectory containing the parser (for monorepos)install_info.generate- Set totrueif the repo doesn’t contain pre-generatedsrc/parser.crequires- Array of languages this parser’s queries inherit fromreadme_note- Additional information for documentation
Troubleshooting
Parser won’t install
- Verify the repository URL is correct and accessible
- Check that the revision/tag exists
- Ensure the repository structure matches (use
locationfor subdirectories)
Queries not working
- Run
make lintqueryto check for invalid captures - Run
make checkqueryto verify patterns match the parser - Use
:InspectTreein Neovim to see the parsed syntax tree - Use
:EditQueryto test query patterns interactively
CI failures
- Ensure your parser repository has the required CI workflows
- Verify the parser supports the latest ABI version
- Check that external scanners are written in C99
External Scanners
External scanners are additional C code that handle complex lexical patterns tree-sitter’s grammar DSL cannot express efficiently.Next Steps
After adding your parser:- Write comprehensive queries
- Add tests to verify functionality
- Monitor issues and PRs related to your language
- Keep queries updated when the parser changes