Skip to main content

NodeKind

Enum NodeKind 

Source
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.

Fields

§statements: Vec<Node>

Statements contained by the program/root node.

§

Block

Block node containing a list of statements.

Fields

§statements: Vec<Node>

Statements inside a block.

§

VariableDeclaration

A single variable declaration (my, our, local, state, …).

Fields

§declarator: String

The declarator keyword (e.g. my, our).

§variable: Box<Node>

The variable node being declared.

§attributes: Vec<String>

Any attributes attached to the declaration.

§initializer: Option<Box<Node>>

Optional initializer expression.

§

VariableListDeclaration

A list-style variable declaration (e.g. my ($a, $b) = ...).

Fields

§declarator: String

The declarator keyword.

§variables: Vec<Node>

Variables declared in the list.

§attributes: Vec<String>

Any attributes attached to the declaration.

§initializer: Option<Box<Node>>

Optional initializer for the list.

§

Variable

A variable usage with sigil and name (e.g. $foo, @arr).

Fields

§sigil: String

The sigil character (e.g. $, @, %).

§name: String

The identifier/name of the variable.

§

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

§message: String

Human readable error message.

§expected: Vec<String>

Tokens or node kinds that were expected at this location.

§partial: Option<Box<Node>>

Optional partially parsed node for recovery contexts.

§

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);
    }
}

Fields

§diag_id: u32

Index into the diagnostics array in ParseOutput.

§

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

§op: String

The operator token as text.

§left: Box<Node>

Left-hand side expression.

§right: Box<Node>

Right-hand side expression.

§

Unary

A unary expression (e.g. -x, !flag).

Fields

§op: String

The operator token.

§operand: Box<Node>

The operand expression.

§

If

An if control-flow construct, including elsif and else branches.

Fields

§condition: Box<Node>

The conditional expression.

§then_branch: Box<Node>

The then-branch block node.

§elsif_branches: Vec<(Node, Node)>

Zero or more elsif branches represented as (condition, block).

§else_branch: Option<Box<Node>>

Optional else branch.

§

Number

Numeric literal node.

Fields

§value: String

The literal text of the number.

§

String

String literal node; may be interpolated.

Fields

§value: String

The string contents.

§interpolated: bool

Whether the string contains interpolation.

§

Identifier

An identifier token.

Fields

§name: String

The identifier text.

Implementations§

Source§

impl NodeKind

Source

pub fn to_sexp(&self) -> String

Convert to S-expression format

Trait Implementations§

Source§

impl Clone for NodeKind

Source§

fn clone(&self) -> NodeKind

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for NodeKind

Source§

fn eq(&self, other: &NodeKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for NodeKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more