tree-sitter-elixir
raw JSON → 0.3.5 verified Sat May 09 auth: no python
Elixir grammar for tree-sitter, providing parsing, syntax highlighting, and code navigation for Elixir files. Current version 0.3.5, requires Python >=3.9. Released irregularly, tied to tree-sitter updates.
pip install tree-sitter-elixir Common errors
error ModuleNotFoundError: No module named 'tree_sitter_elixir' ↓
cause Package not installed.
fix
Run: pip install tree-sitter-elixir
error AttributeError: module 'tree_sitter' has no attribute 'Language' ↓
cause Outdated tree-sitter version (<0.20).
fix
Upgrade tree-sitter: pip install --upgrade tree-sitter
Warnings
breaking Version 0.3.0 changed the Rust crate dependency to tree-sitter-language instead of tree-sitter. Python package may require tree-sitter >=0.21. ↓
fix Ensure tree-sitter is installed at version 0.21 or later: pip install 'tree-sitter>=0.21'
deprecated The built-in queries in 0.3.4 replaced #match? predicates with #any-of?. Custom queries using #match? may need updating. ↓
fix Update custom queries to use #any-of? instead of #match? when matching multiple values.
gotcha The language() function from tree_sitter_elixir is misspelled as 'language' (lowercase 'l') while the official tree-sitter Python binding uses 'Language' (uppercase). This causes confusion. ↓
fix Use 'from tree_sitter_elixir import language' (lowercase) and call language() to get the language object.
Imports
- Language wrong
from tree_sitter_elixir import Languagecorrectfrom tree_sitter_elixir import language
Quickstart
from tree_sitter import Language, Parser
# Load the Elixir language as a shared object
ELIXIR_LANGUAGE = Language('tree_sitter_elixir', 'elixir')
# Create a parser and set the language
parser = Parser()
parser.set_language(ELIXIR_LANGUAGE)
# Parse some Elixir code
tree = parser.parse(b"""
defmodule MyModule do
def hello do
:world
end
end
""")
print(tree.root_node.sexp())