devtools.fm: Developer Tools, Open Source, Software Development

Herrington Darkholme - AST Grep, Searching Code with Code

Mar 4, 2024
Herrington Darkholme, creator of AST Grep and former Vue team member, delves into the future of code searching. He discusses AST Grep's innovative use of abstract syntax trees to improve search efficiency and tackle complex patterns. Darkholme shares insights on crafting YAML-defined rules and the challenges of linting in diverse environments. He also highlights the tool's integration capabilities, including a planned VS Code extension. This is a must-listen for developers seeking to elevate their code search game!
Ask episode
AI Snips
Chapters
Transcript
Episode notes
ANECDOTE

Rust Vue Compiler Sparked AST-Grep

  • Herrington built a Rust-based Vue template compiler and reused input string offsets to avoid allocations for speed.
  • That compiler work inspired the idea of manipulating ASTs and led to creating AST-Grep.
INSIGHT

Search Code By Its AST

  • AST Grep treats code as AST trees rather than plain text, letting you search syntax nodes instead of raw strings.
  • This lets you precisely find code constructs (not comments or strings) with patterns written as code fragments.
INSIGHT

Use Code Fragments As Queries

  • AST-Grep uses code fragments with meta variables as queries so you can "use code to search code."
  • The query is parsed into an AST and meta variables match arbitrary syntax nodes for flexible pattern matching.
Get the Snipd Podcast app to discover more snips from this episode
Get the app