pub enum NodeKind {
Show 18 variants
Program {
statements: Vec<Node>,
},
Block {
statements: Vec<Node>,
},
VariableDeclaration {
declarator: String,
variable: Box<Node>,
attributes: Vec<String>,
initializer: Option<Box<Node>>,
},
VariableListDeclaration {
declarator: String,
variables: Vec<Node>,
attributes: Vec<String>,
initializer: Option<Box<Node>>,
},
Variable {
sigil: String,
name: String,
},
Error {
message: String,
expected: Vec<String>,
partial: Option<Box<Node>>,
},
ErrorRef {
diag_id: u32,
},
MissingExpression,
MissingStatement,
MissingIdentifier,
MissingBlock,
Missing(MissingKind),
Binary {
op: String,
left: Box<Node>,
right: Box<Node>,
},
Unary {
op: String,
operand: Box<Node>,
},
If {
condition: Box<Node>,
then_branch: Box<Node>,
elsif_branches: Vec<(Node, Node)>,
else_branch: Option<Box<Node>>,
},
Number {
value: String,
},
String {
value: String,
interpolated: bool,
},
Identifier {
name: String,
},
}Expand description
The kinds of AST nodes used by the parser.
Each variant represents a specific syntactic construct in the Perl source and carries the child nodes or data needed to represent that construct.
Variants§
Program
Top-level program containing a list of statements.
Block
Block node containing a list of statements.
VariableDeclaration
A single variable declaration (my, our, local, state, …).
Fields
VariableListDeclaration
A list-style variable declaration (e.g. my ($a, $b) = ...).
Fields
Variable
A variable usage with sigil and name (e.g. $foo, @arr).
Fields
Error
An error/recovery node produced during parsing (legacy, rich payload).
This variant embeds the error information directly in the AST node.
For new code, prefer ErrorRef which stores only a diagnostic index.
Fields
ErrorRef
Lightweight error node referencing a diagnostic by index.
This is the preferred error representation for memory efficiency.
The actual diagnostic information is stored in ParseOutput.diagnostics
and can be looked up by the diag_id.
§Example
let output = parser.parse_with_recovery();
for node in output.ast.walk() {
if let NodeKind::ErrorRef { diag_id } = &node.kind {
let diagnostic = &output.diagnostics[*diag_id as usize];
println!("Error at {:?}: {}", node.range, diagnostic);
}
}MissingExpression
Placeholder for a missing expression during error recovery.
MissingStatement
Placeholder for a missing statement during error recovery.
MissingIdentifier
Placeholder for a missing identifier during error recovery.
MissingBlock
Placeholder for a missing block during error recovery.
Missing(MissingKind)
Specific kind of missing syntax element.
This provides more granular information about what’s missing without embedding full diagnostic details in the AST.
Binary
A binary expression (e.g. a + b).
Fields
Unary
A unary expression (e.g. -x, !flag).
If
An if control-flow construct, including elsif and else branches.
Fields
Number
Numeric literal node.
String
String literal node; may be interpolated.
Fields
Identifier
An identifier token.