cangjie-macro

Explain Cangjie macro implementation for compile-time code transformation using token streams and quotes.

4|1|Updated Mar 29, 2026
One-click install
npx skills add https://github.com/JunjieChen0/NJUST --skill cangjie-macro-junjiechen0
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cangjie-macro
Source: https://github.com/JunjieChen0/NJUST/tree/main/.njust-ai/skills/cangjie-macro
Command: npx skills add https://github.com/JunjieChen0/NJUST --skill cangjie-macro-junjiechen0

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers learn and implement the Cangjie macro language for compile-time code transformation, covering tokens, quote expressions, and macro communication, and it explains how to leverage std.ast for parsing and AST manipulation.

Core Features & Use Cases

  • Understand token and Tokens types, and how to manipulate with quote and interpolation.
  • Learn macro definitions for non-attribute and attribute macros, their invocation syntax, and cross-macro communication patterns.
  • Explore nested macros, context passing using setItem/getChildMessages, and diagnostic support during macro expansion.
  • Utilize std.ast to parse, traverse, and transform ASTs for code generation and boilerplate automation.
  • Real-world use: auto-generate boilerplate such as toString, logging, or performance instrumentation at compile time.

Quick Start

Create a small macro package and apply an attribute macro to a class to auto-generate a toString method.

Frequently Asked Questions about cangjie-macro

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

FAQPage Schema
How do I use Cangjie macros for compile-time code generation?

Cangjie macros transform code at compile time by manipulating token streams and using quote expressions. You can define non-attribute and attribute macros to automatically generate boilerplate like toString methods, leveraging the std.ast package for parsing and AST traversal.

How does quote expression interpolation work in Cangjie metaprogramming?

Quote expressions in Cangjie metaprogramming allow you to construct token streams dynamically. By using interpolation within quotes, you can embed variables and tokens directly into code templates, enabling flexible compile-time code transformation and AST manipulation.

Can I pass context between nested macros in Cangjie?

Yes, nested macros in Cangjie support cross-macro communication. You can pass context and share state between macros using setItem and getChildMessages, allowing coordinated compile-time code generation and diagnostic reporting across multiple macro expansions.

What is needed to build an attribute macro package in Cangjie?

Building an attribute macro package in Cangjie requires using the macro package format alongside the std.ast library for parsing. You define the macro to transform AST nodes at compile time, utilizing diagnostic utilities to report errors during the expansion phase.

When should I use Cangjie macros to manipulate the AST?

You should use Cangjie macros when you need to automate boilerplate generation, such as logging or performance instrumentation, at compile time. By traversing and transforming the AST with std.ast, macros eliminate runtime overhead and reduce manual code maintenance.

What is the difference between non-attribute and attribute macros in Cangjie?

Non-attribute macros in Cangjie are invoked like functions, while attribute macros are applied to declarations to transform their AST structure. Both use token streams and quote expressions, but attribute macros allow targeted context passing and code modification for the decorated element.