Supported Programming Languages for the Tree-sitter Parser in code-review-graph
The code-review-graph project supports 25+ programming languages through Tree-sitter, including Python, JavaScript, TypeScript, Go, Rust, Java, C#, Ruby, C/C++, Kotlin, Swift, PHP, and others, with language detection handled via the EXTENSION_TO_LANGUAGE mapping in parser.py.
The code-review-graph repository leverages the Tree-sitter parsing library via the tree_sitter_language_pack package to build language-aware code graphs. It defines a comprehensive mapping between file extensions and grammar identifiers in code_review_graph/parser.py, enabling accurate structural parsing across a multi-language codebase.
Complete List of Tree-sitter Supported Languages
The project maintains an explicit whitelist of languages that have bundled grammars in the tree_sitter_language_pack. These are the languages that receive full AST-based structural analysis.
Core Programming Languages
According to the source code in code_review_graph/parser.py (lines 48-87), the following languages are directly supported with their primary file extensions:
- Python (
.py) - JavaScript (
.js,.jsx) - TypeScript (
.ts,.tsx,.astro) - Go (
.go) - Rust (
.rs) - Java (
.java) - C# (
.cs) - Ruby (
.rb) - C / C++ (
.c,.h,.cpp,.cc,.cxx,.hpp,.hh) - Kotlin (
.kt) - Swift (
.swift) - PHP (
.php) - Scala (
.scala) - Solidity (
.sol) - Vue.js (
.vue) - Dart (
.dart) - R (
.r,.R) - Bash / Shell (
.sh,.bash,.zsh,.ksh) - Elixir (
.ex,.exs) - Zig (
.zig) - PowerShell (
.ps1,.psm1,.psd1) - Svelte (
.svelte) - Julia (
.jl) - Objective-C (
.m) - Lua (
.lua,.luau)
Languages with Fallback Parsing
Some entries in the extension mapping (such as Visual Basic, ReScript, and SQL) are handled by regex-based fallback parsers rather than Tree-sitter grammars. These languages do not receive full AST analysis but are still processed for basic code review tasks.
How Language Detection Works
The detection mechanism relies on a dictionary mapping that links file extensions to Tree-sitter grammar identifiers.
The Extension Mapping Logic
In code_review_graph/parser.py, the EXTENSION_TO_LANGUAGE dictionary (defined at lines 48-87) serves as the single source of truth for language identification:
from code_review_graph.parser import EXTENSION_TO_LANGUAGE
from pathlib import Path
def detect_language(file_path: str) -> str | None:
"""Detect the programming language based on file extension."""
ext = Path(file_path).suffix.lower()
return EXTENSION_TO_LANGUAGE.get(ext)
# Example usage
print(detect_language("example.py")) # → "python"
print(detect_language("script.rb")) # → "ruby"
print(detect_language("app.ts")) # → "typescript"
Jupyter Notebooks and Special Cases
The mapping includes placeholders for special formats like Jupyter notebooks (.ipynb), which require custom parsing logic before Tree-sitter processing can be applied.
Using the Tree-sitter Parser Programmatically
Once a language is identified, the system loads the appropriate Tree-sitter parser for structural analysis.
Loading Parsers by Grammar Name
The internal _load_tree_sitter_parser function instantiates parsers for supported languages:
from code_review_graph.parser import _load_tree_sitter_parser
def parse_source(grammar: str, source: bytes):
"""Parse source code using the specified Tree-sitter grammar."""
parser = _load_tree_sitter_parser(grammar)
if parser is None:
raise RuntimeError(f"No Tree-sitter parser available for {grammar}")
tree = parser.parse(source)
return tree
# Parse a JavaScript file
with open("app.js", "rb") as f:
tree = parse_source("javascript", f.read())
print(tree.root_node.sexp())
This function returns None if the requested grammar is not available in the bundled language pack, allowing callers to implement fallback logic.
Extending Language Support
For languages not included in the default distribution, the project provides an extension point in code_review_graph/custom_languages.py. This file allows developers to register additional Tree-sitter grammars without modifying the core repository or forking the project.
Validation and Testing
The project includes comprehensive test coverage to ensure Tree-sitter parsers load correctly for all supported languages.
Parser Load Verification
The tests/test_parser_load_probe.py file verifies that Tree-sitter grammars are loadable for each language listed in the extension mapping. This ensures that updates to the tree_sitter_language_pack dependency do not break support for existing languages.
Multi-language Parsing Tests
The tests/test_multilang.py suite contains language-specific test cases that validate correct Tree-sitter parsing across the supported language set, ensuring that AST construction produces expected node types for each grammar.
Summary
- code-review-graph supports 25+ languages via the
tree_sitter_language_pack, including Python, JavaScript, TypeScript, Go, Rust, Java, C#, Ruby, C/C++, Kotlin, Swift, PHP, Scala, Solidity, Vue, Dart, R, Shell, Elixir, Zig, PowerShell, Svelte, and Julia. - Language detection occurs through the
EXTENSION_TO_LANGUAGEmapping defined incode_review_graph/parser.pyat lines 48-87. - The
_load_tree_sitter_parserfunction instantiates parsers by grammar name, returningNonefor unsupported languages. - Languages without Tree-sitter grammars fall back to regex-based parsing.
- Custom languages can be added via
code_review_graph/custom_languages.pywithout forking the repository.
Frequently Asked Questions
Which file defines the supported programming languages in code-review-graph?
The EXTENSION_TO_LANGUAGE dictionary in code_review_graph/parser.py (lines 48-87) defines the complete mapping of file extensions to Tree-sitter grammar identifiers. This dictionary determines which files receive AST-based structural parsing versus regex-based fallback processing.
How does code-review-graph handle file extensions for C and C++?
The parser recognizes multiple C and C++ extensions including .c, .h, .cpp, .cc, .cxx, .hpp, and .hh. These extensions map to the appropriate C or C++ Tree-sitter grammars, allowing the system to parse header files and implementation files with correct language semantics.
Can I add support for a language not included in the Tree-sitter language pack?
Yes. The code_review_graph/custom_languages.py module provides an extension point for registering additional Tree-sitter grammars. You can add custom language support by importing your grammar and registering it with the parser system without modifying the core codebase or maintaining a fork.
What happens when Tree-sitter encounters an unsupported language?
When a file extension maps to a language without a bundled Tree-sitter grammar, the _load_tree_sitter_parser function returns None. The system then falls back to regex-based parsing for basic code analysis, or skips structural parsing entirely depending on the configuration in the extension mapping.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →