tree-sitter-solidity

A low-dependency Tree-sitter grammar for Solidity, designed for metaprogramming and tooling.

Library
Cargo
v1.2.13
186stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
44/100Fair
Development Activity4
Maintenance20
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture74
Code Quality70
Innovation72
Learning Curve76

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::LanguageFn for 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search