crystal-macros

Generate Crystal code at compile time using macros.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill crystal-macros
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: crystal-macros
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-crystal/skills/crystal-macros
Command: npx skills add https://github.com/TheBushidoCollective/han --skill crystal-macros

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

You harness Crystal's macro system for compile-time code generation, DSL creation, and AST manipulation to build powerful abstractions with zero runtime overhead.

Core Features & Use Cases

  • Macro-based code generation and boilerplate reduction
  • DSLs built with macro methods for expressive APIs
  • Compile-time computations, validations, and AST manipulation
  • Serialization/deserialization code generation
  • Debugging and introspection tooling

Quick Start

Define a simple macro to generate getters or setters, then use macro expansion to create boilerplate code at compile time.

Frequently Asked Questions about crystal-macros

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

FAQPage Schema
How do I use Crystal macros to generate code at compile time?

Crystal macros generate code at compile time by inspecting and transforming the AST. Define a macro with the `macro` keyword, use `{% %}` for compile-time logic, and `{{ }}` to interpolate generated code. The compiler expands macros before runtime, eliminating boilerplate and enabling zero-cost abstractions.

Can I build a DSL using Crystal macros?

Yes. Crystal macros enable DSL creation through macro methods that accept blocks and transform them into expressive APIs. Use macros to interpret domain-specific syntax at compile time, generate validation logic, and produce type-safe abstractions without runtime overhead.

What can Crystal macros generate besides methods?

Crystal macros generate classes, modules, serializers, configuration flags, and validation logic. Use string interpolation and conditional compilation within macros to create entire class hierarchies, implement custom serialization, or inject compile-time validations based on type information.

How does compile-time AST manipulation reduce boilerplate in Crystal?

AST manipulation lets macros inspect type definitions and automatically generate repeated patterns—getters, setters, serializers—without manual coding. The macro system accesses method signatures and type metadata at compile time, generating exact code needed and shrinking source files.

When should I use macros instead of runtime reflection in Crystal?

Use macros when you need zero runtime overhead, type safety at compile time, or code generation that depends on surrounding context. Macros execute before runtime, catching errors early and producing optimized code; runtime reflection adds overhead and loses compile-time guarantees.