pub struct ParseOutput {
pub ast: Node,
pub diagnostics: Vec<ParseError>,
pub budget_usage: BudgetTracker,
pub terminated_early: bool,
pub recovered_count: usize,
}Expand description
Structured output from parsing, combining AST with all diagnostics.
This type replaces the simple Result<Node, ParseError> pattern to enable
error recovery. Even when errors occur, parsing continues and produces a
partial AST alongside collected diagnostics.
§Usage
use perl_parser::{Parser, ParseOutput};
let mut parser = Parser::new("my $x = ;");
let output = parser.parse_with_recovery();
// AST is always available (may contain error nodes)
println!("Statements: {:?}", output.ast);
// Diagnostics are collected separately
for error in &output.diagnostics {
println!("Error: {}", error);
}
// Budget tracking shows resource usage
println!("Errors: {}", output.budget_usage.errors_emitted);Fields§
§ast: NodeThe parsed AST. Always present, but may contain error nodes if parsing encountered recoverable errors.
diagnostics: Vec<ParseError>All diagnostics (errors and warnings) collected during parsing. These are ordered by source position.
budget_usage: BudgetTrackerBudget consumption during this parse. Useful for diagnosing pathological inputs.
terminated_early: boolWhether parsing completed normally or was terminated early due to budget exhaustion.
recovered_count: usizeNumber of recovery operations applied during this parse.
Counts the ParseError::Recovered variants in diagnostics.
LSP providers use this as a confidence signal: 0 means a clean parse,
> 0 means at least one synthetic repair was made.
Implementations§
Source§impl ParseOutput
impl ParseOutput
Sourcepub fn success(ast: Node) -> ParseOutput
pub fn success(ast: Node) -> ParseOutput
Create a successful parse output with no errors.
Sourcepub fn with_errors(ast: Node, diagnostics: Vec<ParseError>) -> ParseOutput
pub fn with_errors(ast: Node, diagnostics: Vec<ParseError>) -> ParseOutput
Create a parse output with errors.
Note: This re-derives budget_usage from diagnostics count.
For accurate budget tracking, use finish() instead.
Sourcepub fn finish(
ast: Node,
diagnostics: Vec<ParseError>,
budget_usage: BudgetTracker,
terminated_early: bool,
) -> ParseOutput
pub fn finish( ast: Node, diagnostics: Vec<ParseError>, budget_usage: BudgetTracker, terminated_early: bool, ) -> ParseOutput
Create a parse output with full budget tracking.
This is the preferred constructor when the actual BudgetTracker from parsing is available, as it preserves accurate metrics.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Check if parse had errors.
Sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
Get the error count.
Trait Implementations§
Source§impl Clone for ParseOutput
impl Clone for ParseOutput
Source§fn clone(&self) -> ParseOutput
fn clone(&self) -> ParseOutput
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more