<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: treesitter</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/treesitter.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2023-12-10T19:56:10+00:00</updated><author><name>Simon Willison</name></author><entry><title>ast-grep</title><link href="https://simonwillison.net/2023/Dec/10/ast-grep/#atom-tag" rel="alternate"/><published>2023-12-10T19:56:10+00:00</published><updated>2023-12-10T19:56:10+00:00</updated><id>https://simonwillison.net/2023/Dec/10/ast-grep/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://ast-grep.github.io/"&gt;ast-grep&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
There are a lot of interesting things about this year-old project.&lt;/p&gt;

&lt;p&gt;sg (an alias for ast-grep) is a CLI tool for running AST-based searches against code, built in Rust on top of the Tree-sitter parsing library. You can run commands like this:&lt;/p&gt;

&lt;p&gt;sg -p ’await await_me_maybe($ARG)’ datasette --lang python&lt;/p&gt;

&lt;p&gt;To search the datasette directory for code that matches the search pattern, in a syntax-aware way.&lt;/p&gt;

&lt;p&gt;It works across 19 different languages, and can handle search-and-replace too, so it can work as a powerful syntax-aware refactoring tool.&lt;/p&gt;

&lt;p&gt;My favourite detail is how it’s packaged. You can install the CLI utility using Homebrew, Cargo, npm or pip/pipx—each of which will give you a CLI tool you can start running. On top of that it provides API bindings for Rust, JavaScript and Python!

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://news.ycombinator.com/item?id=38590984"&gt;Hacker News&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/cli"&gt;cli&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/javascript"&gt;javascript&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/search"&gt;search&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/tools"&gt;tools&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/rust"&gt;rust&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/treesitter"&gt;treesitter&lt;/a&gt;&lt;/p&gt;



</summary><category term="cli"/><category term="javascript"/><category term="python"/><category term="search"/><category term="tools"/><category term="rust"/><category term="treesitter"/></entry></feed>