Skip to content

Tree-Sitter Parser

chimera.tools.parsers.tree_sitter provides multi-language AST parsing via tree-sitter. It extracts function, class, method, struct, trait, and enum symbols from source files across 18+ languages. Tree-sitter is an optional dependency — the parser degrades gracefully when it is not installed.

Class / FunctionDescription
TreeSitterParserPolyglot AST parser supporting 18+ languages
tree_sitter_available()Check if tree-sitter is installed
get_parser(extension)Get the best available parser (tree-sitter or regex fallback)

Python, JavaScript, TypeScript, TSX, JSX, Go, Rust, Java, C, C++, Ruby, PHP, Swift, Kotlin, Scala, C# — determined by file extension.

from chimera.tools.parsers.tree_sitter import TreeSitterParser, get_parser
parser = TreeSitterParser()
if parser.can_parse(".py"):
symbols = parser.parse("class Foo:\n def bar(self): ...", extension=".py")
for sym in symbols:
print(f"{sym.kind}: {sym.name}")
for child in sym.children:
print(f" {child.kind}: {child.name}")

get_parser() returns tree-sitter when available, otherwise falls back to the built-in regex parsers for Python, TypeScript, Go, and Rust:

parser = get_parser(".rs") # TreeSitterParser or RustParser
if parser:
symbols = parser.parse(source, ".rs")
KindNode Types
functionfunction_definition, function_declaration, arrow_function
methodmethod_definition, method_declaration
classclass_definition, class_declaration
structstruct_item, struct_declaration
interfaceinterface_declaration
traittrait_item
enumenum_item, enum_declaration
implimpl_item
from chimera.tools.parsers.tree_sitter import TreeSitterParser, tree_sitter_available, get_parser
from chimera.tools.parsers.base import LanguageParser, Symbol