@olyno/tree-sitter-vyper
v0.1.1
Published
Vyper grammar for tree-sitter
Maintainers
Readme
tree-sitter-vyper
Vyper grammar for tree-sitter.
Forked from tree-sitter-python, rewritten for the Vyper smart contract language.
Supported constructs
event,struct,interfacewith member definitionsenumwith member valueslogstatementextcallandstaticcallas assignable expressionsfor i: uint256 in range(...)with typed loop variables- All standard Vyper syntax: functions, decorators, imports, type annotations, etc.
Installation
Node.js (WASM)
npm install @olyno/tree-sitter-vyperconst Parser = require("tree-sitter");
const Vyper = require("@olyno/tree-sitter-vyper");
const parser = new Parser();
parser.setLanguage(Vyper);
const tree = parser.parse(`event Transfer:
sender: indexed(address)
receiver: indexed(address)
value: uint256
`);
console.log(tree.rootNode.toString());The Node binding is WASM-only — no native compilation, no node-gyp.
Requires tree-sitter ^0.25.0 as a peer dependency.
Rust
Add to Cargo.toml:
[dependencies]
tree-sitter = "0.25"
tree-sitter-vyper = { git = "https://github.com/Olyno/tree-sitter-vyper" }use tree_sitter::Parser;
let mut parser = Parser::new();
parser.set_language(&tree_sitter_vyper::LANGUAGE.into())?;
let tree = parser.parse("x: uint256 = 42", None).unwrap();
println!("{}", tree.root_node().to_sexp());Building from source
Prerequisites
- Node.js ≥ 18
- tree-sitter-cli (
npm install -g tree-sitter-cliornpx tree-sitter)
Generate the parser
tree-sitter generateRun tests
tree-sitter testBuild WASM
tree-sitter build --wasmThis produces tree-sitter-vyper.wasm — use it with Parser.Language.load():
const Vyper = await Parser.Language.load("./tree-sitter-vyper.wasm");
parser.setLanguage(Vyper);Rust tests
cargo testQueries
The grammar ships with:
| File | Purpose |
|---|---|
| queries/highlights.scm | Syntax highlighting |
| queries/tags.scm | Symbol tagging (outline, breadcrumbs) |
| queries/indents.scm | Indentation rules |
| queries/folds.scm | Code folding |
References
License
MIT — see LICENSE.
