View on GitHub

Graft Documentation

Safe, structural code transformation using Tree-sitter

Graft

Graft is a robust CLI tool for safe, structural code transformation powered by Tree-sitter.

Unlike traditional regex-based find-and-replace tools, Graft operates on the Abstract Syntax Tree (AST). This ensures that your code modifications are syntactically valid and aware of the code’s actual structure.

Key Features

Quick Start

Transform addition into a function call in a Rust file:

graft src/main.rs \
  --query '(binary_expression left: (_) @l operator: "+" right: (_) @r) @target' \
  --template 'add(${l}, ${r})'

LICENSE

MIT