ast-grep

Translate natural language queries into ast-grep YAML rules for structural code search.

Updated Mar 12, 2019
One-click install
npx skills add https://github.com/gustavofsantos/dot-files --skill ast-grep-gustavofsantos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/gustavofsantos/dot-files/tree/main/skills/ast-grep
Command: npx skills add https://github.com/gustavofsantos/dot-files --skill ast-grep-gustavofsantos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Translate natural language queries into ast-grep rules for structural code search.

Core Features & Use Cases

  • Translate NL queries into ast-grep rules to search code by structure rather than text, enabling precise matches.
  • Create sample test files and simple rules to validate queries against real code snippets.
  • Step through a practical workflow: understand the query, draft a rule, test against code, and apply to a repository.

Quick Start

Describe the code pattern you want to match, and I will generate an ast-grep rule and guide you through testing it.

Frequently Asked Questions about ast-grep

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I search code by structure instead of text matching?

Structure-aware code search uses AST patterns and metavariables to match code syntax precisely. You translate natural language queries into ast-grep rules, enabling structural matches across language trees rather than relying on flat text matching.

What are ast-grep rules and how do they use metavariables?

Ast-grep rules are YAML syntax configurations that define structural code search patterns using metavariables. Metavariables act as wildcards within AST patterns, allowing you to capture and match variable code elements within a defined syntactic structure.

How do I translate a natural language query into an ast-grep rule?

To translate natural language queries into ast-grep rules, describe the code pattern you want to match. The tool drafts a YAML rule satisfying the syntax, then provides testing steps to validate the pattern against real code snippets in a repository.

How do I test and refine structural code search rules against a real codebase?

You test structural code search rules by creating sample test files and applying the ast-grep rule to a real codebase. The workflow involves drafting a rule, testing it against code snippets, and iteratively refining the YAML pattern for precise matches.

Does ast-grep work for static analysis across different programming languages?

Ast-grep performs static analysis by applying structure-aware rules across language trees. By leveraging AST patterns, it validates code structures and enforces rules regardless of specific text formatting variations in the codebase.

What is the best way to validate AST patterns before applying them to a repository?

The best way to validate AST patterns is by creating simple sample test files with expected code snippets. You draft an ast-grep rule, test it against these snippets, and iteratively refine the YAML syntax before applying it to the full repository.