cangjie-macro

Guide Cangjie macro definition and AST manipulation for compile-time code generation.

2|Updated Mar 10, 2026
One-click install
npx skills add https://github.com/zhenzhizhi12/NexusAgent --skill cangjie-macro-zhenzhizhi12
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cangjie-macro
Source: https://github.com/zhenzhizhi12/NexusAgent/tree/main/.opencode/skills/common-skill-l1/macro
Command: npx skills add https://github.com/zhenzhizhi12/NexusAgent --skill cangjie-macro-zhenzhizhi12

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill empowers developers to write powerful compile-time code generation using Cangjie language macros, reducing boilerplate and increasing code efficiency.

Core Features & Use Cases

  • Macro Definition: Learn to define non-attribute, attribute, nested, and communicating macros.
  • AST Manipulation: Understand how to parse, traverse, and generate Abstract Syntax Tree (AST) nodes for code transformation.
  • Use Case: Automatically generate toString() methods for classes, implement compile-time memoization for functions, or create domain-specific language (DSL) extensions within Cangjie.

Quick Start

Use the cangjie-macro skill to understand how to define a non-attribute macro that automatically generates a toString method for a Cangjie class.

Frequently Asked Questions about cangjie-macro

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

FAQPage Schema
How do I generate code automatically using Cangjie macros?

Cangjie macros enable compile-time code generation by defining non-attribute, attribute, or nested macros to transform AST nodes, reducing boilerplate. You parse and traverse Abstract Syntax Tree nodes using `std.ast` to automate tasks like generating `toString` methods.

How does AST manipulation work for metaprogramming in Cangjie?

AST manipulation in Cangjie involves parsing tokenized code into Abstract Syntax Tree nodes, traversing these nodes, and applying transformations using `std.ast`. This metaprogramming mechanism allows developers to modify code structure during compilation for custom DSL creation.

What are the different types of macros I can define in the Cangjie language?

In the Cangjie language, you can define non-attribute macros, attribute macros, nested macros, and communicating macros. These macro types facilitate advanced metaprogramming by allowing developers to intercept and transform code at compile-time.

When do I need to use compile-time macros instead of regular functions in Cangjie?

You need compile-time macros in Cangjie when you want to reduce boilerplate code, implement compile-time memoization, or create domain-specific language (DSL) extensions. Macros operate on the AST during compilation, allowing code generation before runtime execution.

Can I use Cangjie macros to automatically generate a toString method for classes?

Yes, you can define a non-attribute macro in Cangjie to automatically generate a `toString` method for classes. By manipulating AST nodes during compilation, the macro injects the method definition dynamically, eliminating manual boilerplate code.

What is the best way to create a domain-specific language extension in Cangjie?

The best way to create a domain-specific language (DSL) extension in Cangjie is by using macros for metaprogramming. By defining nested or attribute macros and manipulating the AST via `std.ast`, you can translate custom DSL syntax into standard Cangjie code at compile-time.