Token and Tokens Types
Tokens is the fundamental type for Cangjie macro operations, representing a program fragment. A Tokens consists of multiple Token objects, where each Token is a lexical unit: an identifier, literal, keyword, or operator.
Each Token contains a type (kind, taking a TokenKind enum value) and content (value). You can manually construct any Token using Token(kind, value), for example Token(TokenKind.IDENTIFIER, "x") constructs the identifier x.
Tokens supports concatenation operations: + can concatenate two Tokens, or concatenate Tokens with a Token. The code on the right demonstrates how to manually construct three Token objects and combine them into a Tokens representing 1 + 2, then iterate through to view each Token's type and value.
Modify the Token construction parameters by changing "1" to "42" and observe the output changes.
Token also has position information (line number, column number) used for compile error location. The dump() method can print complete debug information.