Quote Expression
Manually constructing each Token is tedious and error-prone. Cangjie provides the quote(...) expression, allowing you to easily build Tokens using code templates.
quote captures a code fragment as a Tokens value without executing it. Inside a macro, you use quote to construct the code that the macro returns. In the example on the right, the PrintExpr macro receives input Tokens, wraps them with quote into a println(...) call, and returns it.
When a quote expression contains certain special symbols, they need to be escaped: unmatched parentheses are escaped with \( or \); when $ represents a literal character rather than interpolation, use \$ to escape it.
Try adding a second line println("extra") in the quote(...) block, then run to see the output changes after macro expansion.
macro package and compiled with the --compile-macro option.define.cj and the commented usage example as main.cj. Run cjc define.cj --compile-macro, then cjc main.cj --import-path . -o main && ./main. The online single-file runner does not support this multi-file build step.