ast-grep

Translate natural language queries into ast-grep AST pattern rules for Tree-sitter languages.

203|9|Updated Dec 23, 2019
One-click install
npx skills add https://github.com/elianiva/dotfiles --skill ast-grep-elianiva
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/elianiva/dotfiles/tree/main/agents/skills/ast-grep
Command: npx skills add https://github.com/elianiva/dotfiles --skill ast-grep-elianiva

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps users construct robust, structural searches of source code using AST patterns, enabling precise finding of code structures beyond plain text.

Core Features & Use Cases

  • Rule translation: Convert natural language queries into ast-grep rules for structural code search.
  • Language awareness: Support for languages governed by Tree-sitter grammars to match language constructs.
  • Use Case: Identify specific patterns such as async functions with awaits or class method patterns across large codebases.

Quick Start

Describe a target language and a code snippet, and I will generate an ast-grep rule to match the pattern.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I search for specific code patterns using AST instead of plain text?

AST searches match code structure using Tree-sitter grammars, enabling precise finding of language constructs beyond plain text. You translate natural language queries into ast-grep rules to identify specific patterns like async functions with awaits across large codebases.

What is the best way to find async functions with awaits across a large codebase?

The best way to find async functions with awaits is using structural code search with ast-grep rules. This approach matches code structure via AST patterns rather than text strings, correctly identifying the targeted language constructs across your entire codebase.

Does ast-grep work with any programming language or do I need specific grammars?

ast-grep works with any language supported by Tree-sitter grammars. You must specify the target language when constructing structural search rules, allowing the AST parser to correctly interpret and match the language-specific code constructs.

How do I validate and test ast-grep rules to ensure they match code correctly?

You validate and test ast-grep rules using the ast-grep CLI to verify rule correctness. This involves running the generated structural search rules against your codebase to confirm they accurately match the intended code patterns and handle defined edge cases.

How do I translate a natural language code query into a structural search rule?

You translate a natural language query into a structural search rule by describing a target language and a code snippet. The Skill generates an ast-grep rule specifying the language, target scope, and edge cases to match the desired code structure.

What are the limitations of using AST patterns for code search?

AST pattern code search is limited by Tree-sitter grammar support and requires specifying the target language. Complex structural queries need careful edge case definition and CLI validation to avoid over-matching or missing intended code constructs.