Syntax Tree Node Print
The Cangjie ast package provides various syntax tree nodes to represent Cangjie source code. Various types of nodes and different attributes of different nodes may cause confusion. Therefore, the dump
function is implemented for each AST node to view the overall structure of syntax tree nodes in real time, avoiding repeated reading of this manual.
Example:
import std.ast.*
main() {
let input = quote(var demo: Int64 = 1) // Assume that the current code is in line 3.
let varDecl = parseDecl(input)
varDecl.dump()
}
Running result:
VarDecl {
-keyword: Token {
value: "var"
kind: VAR
pos: 3: 23
}
-identifier: Token {
value: "demo"
kind: IDENTIFIER
pos: 3: 27
}
-declType: PrimitiveType {
-keyword: Token {
value: "Int64"
kind: INT64
pos: 3: 33
}
}
-assign: Token {
value: "="
kind: ASSIGN
pos: 3: 39
}
-expr: LitConstExpr {
-literal: Token {
value: "1"
kind: INTEGER_LITERAL
pos: 3: 41
}
}
}