tree-sitter-solidity
A low-dependency Tree-sitter grammar for Solidity, designed for metaprogramming and tooling.
Repository Health
Technical Analysis
tree-sitter-solidity is a Tree-sitter grammar for Solidity, the smart-contract language for Ethereum and EVM chains. It parses contract source into a fast, incrementally-updated concrete syntax tree that editors and analysis tools can walk for highlighting, navigation, and metaprogramming.
The grammar aims to be an efficient, low-dependency parser that targets most Solidity versions in use, and ships bindings for Rust, C, Node, and other Tree-sitter hosts from a single definition.
What You Get
- A Tree-sitter grammar for Solidity targeting most versions in use, compiled to a portable C parser.
- A Rust binding exposing the parser as a
tree_sitter_language::LanguageFnfor the Tree-sitter runtime. - Highlight and injection query files ready for editor integration.
- A low-dependency parse tree suitable for metaprogramming and static analysis.
Common Use Cases
- Syntax highlighting for .sol files in editors like Neovim.
- Structural navigation, folding, and text objects over Solidity contracts.
- Static analysis, linting, and metaprogramming tools that need a Solidity parse tree.
Under The Hood
Architecture - The grammar is authored in grammar.js using Tree-sitter’s DSL and compiled to a portable src/parser.c plus src/node-types.json; language bindings each wrap that generated parser, and query files provide editor highlighting. The grammar draws structure and inspiration from tree-sitter-javascript and Ethereum’s official Solidity ANTLR grammar.
Tech Stack - The Rust binding (built via build.rs with the cc crate) depends on tree-sitter-language at runtime and tree-sitter for testing; the repo also carries npm and other manifests so one grammar serves multiple ecosystems, with Node.js CI validating changes.
Code Quality - Correctness is anchored by an extensive Tree-sitter test corpus under test/, exercised through the standard tree-sitter test harness; the README notes the generated AST structure is still stabilizing, so tests are the primary contract.
API Design - The public surface follows Tree-sitter conventions: the crate exports a LANGUAGE constant (LanguageFn) and query strings, so anyone familiar with the ecosystem can wire it into a parser in a few lines.