std.ast Package

Function Description

The ast package contains the syntax parser of Cangjie source code and Cangjie syntax tree nodes, and provides syntactic parsing functions. It can parse lexical units (Tokens) of Cangjie source code to node objects of the abstract syntax tree.

The Cangjie ast package provides functions related to Macro With Context used to obtain the context information during macro expansion. In the nested macro scenario, an inner macro can call the library function assertParentContext(String) to ensure that the inner macro call is nested in a specific outer macro call. If the call of this function by the inner macro is not nested within the given outer macro call, the function throws an error. In addition, the insideParentContext(String) function is also used to check whether an inner macro call is nested in a specific outer macro call and return a Boolean value. Functions related to Macro With Context can only be directly called as functions, do not support variable assignment, and cannot be used as actual parameters or return values.

The functions related to Macro With Context are as follows:

API List

Function

NameDescription
assertParentContext(String)  Checks whether the current macro call is within a specific macro call. If the check result does not meet the expectation, the compiler displays an error message.
cangjieLex(String)  Converts a string to a value of the Tokens type.
cangjieLex(String, Bool)  Converts a string to a value of the Tokens type.
compareTokens(Tokens, Tokens)  Checks whether two Tokens are the same.
diagReport(DiagReportLevel, Tokens, String, String)  Specifies an error reporting API used to output error messages during macro expansion in the compilation process. WARNING and ERROR messages are supported.
getChildMessages(String)  Obtains information sent by a specific inner macro.
getTokenKind(UInt16)  Converts a sequence number of the lexical unit type to TokenKind.
insideParentContext(String)  Checks whether the current macro call is within a specific macro call and returns a Boolean value.
parseDecl(Tokens, String)  Parses a group of lexical units to obtain a node of the Decl type.
parseDeclFragment(Tokens, Int64)  Parses a group of lexical units to obtain a node of the Decl type and an index for continuing node parsing.
parseExpr(Tokens)  Parses a group of lexical units to obtain a node of the Expr type.
parseExprFragment(Tokens, Int64)  Parses a group of lexical units to obtain a node of the Expr type and an index for continuing node parsing.
parseProgram(Tokens)  Parses the source code of a single Cangjie file to obtain a node of the Program type.
setItem(String, Bool)  Sends information of the Bool type from an inner macro to an outer macro.
setItem(String, Int64)  Sends information of the Int64 type from an inner macro to an outer macro.
setItem(String, String)  Sends information of the String type from an inner macro to an outer macro.

Interface

NameDescription
ToBytesProvides the serialization function of the corresponding type.
ToTokensConverts an instance type to the Tokens type. To support the quote interpolation operation, this interface must be implemented.

Class

NameDescription
AnnotationSpecifies a built-in annotation node of the compiler.
ArgumentSpecifies an argument node in function call.
ArrayLiteralSpecifies an Array literal node.
AsExprSpecifies a type check expression.
AssignExprSpecifies an assignment expression node.
BinaryExprSpecifies a binary operation expression node.
BlockSpecifies a block node.
BodySpecifies a structure of the Class, Struct, or Interface type with an extension containing {} and a group of declaration nodes enclosed therein.
CallExprSpecifies a function call node.
ClassDeclSpecifies a class definition node.
ConstPatternSpecifies a constant pattern node.
ConstructorSpecifies a Constructor node of the enum type.
DeclSpecifies the parent class of all declaration nodes, which is inherited from the Node and provides the common API for all declaration nodes.
DoWhileExprSpecifies a do-while expression.
EnumDeclSpecifies an Enum definition node.
EnumPatternSpecifies an enum pattern node.
ExceptTypePatternSpecifies a node used in exception pattern.
ExprSpecifies the parent class of all expression nodes, which is inherited from the Node.
ExtendDeclSpecifies an extension definition node.
ForInExprSpecifies a for-in expression.
FuncDeclSpecifies a function definition node.
FuncParamSpecifies a function parameter node, including unnamed parameters and named parameters.
FuncTypeSpecifies a function type node.
GenericConstraintSpecifies a generic constraint node.
GenericParamSpecifies a type formal parameter node.
IfExprSpecifies a condition expression.
ImportContentSpecifies an import item in the package import node.
ImportListSpecifies a package import node.
IncOrDecExprSpecifies an expression that contains an auto-increment operator (++) or auto-decrement operator (--).
InterfaceDeclSpecifies an API definition node.
IsExprSpecifies a type check expression.
JumpExprSpecifies break and continue in the loop body of a loop expression.
LambdaExprSpecifies a Lambda expression, which is an anonymous function.
LetPatternExprSpecifies a deconstruction match node declared by let.
LitConstExprSpecifies a constant expression node.
MacroDeclSpecifies a macro definition node.
MacroExpandDeclSpecifies a macro call node.
MacroExpandExprSpecifies a macro call node.
MacroExpandParamSpecifies a macro call node.
MacroMessageRecords information sent by an inner macro.
MainDeclSpecifies a main function definition node.
MatchCaseSpecifies a case node in a match expression.
MatchExprSpecifies that a pattern matching expression implements pattern matching.
MemberAccessSpecifies a member access expression.
ModifierSpecifies that a definition has certain features. It is usually placed at the beginning of a definition.
NodeSpecifies the parent class of all Cangjie syntax tree nodes.
OptionalExprSpecifies an expression node with a question mark (?).
PackageHeaderSpecifies a package declaration node.
ParenExprSpecifies a parenthesis expression node, which is an expression enclosed in parentheses.
ParenTypeSpecifies a parenthesis type node.
PatternSpecifies the parent class of all pattern matching nodes, which is inherited from the Node.
PrefixTypeSpecifies a prefix type node with a question mark (?).
PrimaryCtorDeclSpecifies a primary constructor node.
PrimitiveTypeSpecifies a primitive type node.
PrimitiveTypeExprSpecifies a primitive type expression node.
ProgramSpecifies a Cangjie source code file node.
PropDeclSpecifies a property definition node.
QualifiedTypeSpecifies a user-defined member type.
QuoteExprSpecifies a quote expression node.
QuoteTokenSpecifies any valid token in a quoteexpression node.
RangeExprSpecifies an expression that contains range operators.
RefExprSpecifies an expression node related to a node of a user-defined type.
RefTypeSpecifies a user-defined type node.
ReturnExprSpecifies a return expression node.
SpawnExprSpecifies a Spawn expression.
StructDeclSpecifies a Struct node.
SubscriptExprSpecifies an index access expression.
SynchronizedExprSpecifies a synchronized expression.
ThisTypeSpecifies a This type node.
ThrowExprSpecifies a throw expression node.
TokensSpecifies a type for encapsulating Token sequences.
TokensIteratorImplements the iterator function of Tokens.
TrailingClosureExprSpecifies a trailing Lambda node.
TryExprSpecifies a try expression node.
TupleLiteralSpecifies a tuple literal node.
TuplePatternSpecifies a Tuple pattern node.
TupleTypeSpecifies a tuple type node.
TypeAliasDeclSpecifies a type alias node.
TypeConvExprSpecifies a type conversion expression.
TypeNodeSpecifies the parent class of all type nodes, which is inherited from Node.
TypePatternSpecifies a type pattern node.
UnaryExprSpecifies a unary operation expression node.
VArrayExprSpecifies a VArray instance node.
VArrayTypeSpecifies a VArray type node.
VarDeclSpecifies a variable definition node.
VarOrEnumPatternSpecifies a node when the pattern identifier is an Enum constructor.
VarPatternSpecifies a binding pattern node.
VisitorSpecifies an abstract class that defines default visit functions for accessing different types of AST nodes.
WhileExprSpecifies a while expression.
WildcardExprSpecifies a wildcard expression node.
WildcardPatternSpecifies a wildcard pattern node.

Enumeration

NameDescription
DiagReportLevelSpecifies information levels supported by an error reporting API. ERROR and WARNING are supported.
ImportKindSpecifies the type of an import statement, including single import, alias import, full import, and multi-import.
TokenKindSpecifies all lexical structures in Cangjie compilation, including symbols, keywords, identifiers, and line breaks.

Struct

NameDescription
PositionSpecifies the data structure of location information, including the file ID, row number, and column number.
TokenSpecifies the lexical unit type.

Exception Class

NameDescription
ASTExceptionSpecifies an exception class for the ast library, which is used when an exception occurs during ast library invocation.
MacroContextExceptionSpecifies a context macro exception class for the ast library, which is used when an exception occurs in context macro-related APIs.
ParseASTExceptionSpecifies a parsing exception class for the ast library, which is used when an exception occurs during node parsing.