Expand description
Error types for the Perl parser within the Perl parsing workflow pipeline
This module defines comprehensive error handling for Perl parsing operations that occur throughout the Perl parsing workflow workflow: Parse → Index → Navigate → Complete → Analyze.
§Error Recovery Strategy
When parsing errors occur during Perl parsing:
- Parse stage: Parsing failures indicate corrupted or malformed Perl source
- Analyze stage: Syntax errors suggest script inconsistencies requiring fallback processing
- Navigate stage: Parse failures can break thread analysis - graceful degradation applies
- Complete stage: Errors impact output generation but preserve original content
- Analyze stage: Parse failures affect search indexing but maintain basic metadata
§Performance Context
Error handling is optimized for large Perl codebase processing scenarios with minimal memory overhead and fast recovery paths to maintain enterprise-scale performance targets.
§Usage Examples
§Basic Error Handling
ⓘ
use perl_parser::{Parser, ParseError, ParseResult};
fn parse_with_error_handling(code: &str) -> ParseResult<()> {
let mut parser = Parser::new(code);
match parser.parse() {
Ok(ast) => {
println!("Parsing successful");
Ok(())
}
Err(ParseError::UnexpectedEof) => {
eprintln!("Incomplete code: unexpected end of input");
Err(ParseError::UnexpectedEof)
}
Err(ParseError::UnexpectedToken { found, expected, location }) => {
eprintln!("Syntax error at position {}: found '{}', expected '{}'",
location, found, expected);
Err(ParseError::UnexpectedToken { found, expected, location })
}
Err(e) => {
eprintln!("Parse error: {}", e);
Err(e)
}
}
}§Error Recovery in LSP Context
ⓘ
use perl_parser::{Parser, ParseError, error_recovery::ErrorRecovery};
fn parse_with_recovery(code: &str) -> Vec<String> {
let mut parser = Parser::new(code);
let mut errors = Vec::new();
match parser.parse() {
Ok(_) => println!("Parse successful"),
Err(err) => {
// Log error for diagnostics
errors.push(format!("Parse error: {}", err));
// Attempt error recovery for LSP
match err {
ParseError::UnexpectedToken { .. } => {
// Continue parsing from next statement
println!("Attempting recovery...");
}
ParseError::RecursionLimit => {
// Use iterative parsing approach
println!("Switching to iterative parsing...");
}
_ => {
// Use fallback parsing strategy
println!("Using fallback parsing...");
}
}
}
}
errors
}§Comprehensive Error Context
use perl_error::ParseError;
fn create_detailed_error() -> ParseError {
ParseError::UnexpectedToken {
found: "number".to_string(),
expected: "identifier".to_string(),
location: 10, // byte position 10
}
}
fn handle_error_with_context(error: &ParseError) {
match error {
ParseError::UnexpectedToken { found, expected, location } => {
println!("Syntax error at byte position {}: found '{}', expected '{}'",
location, found, expected);
}
ParseError::UnexpectedEof => {
println!("Incomplete input: unexpected end of file");
}
_ => {
println!("Parse error: {}", error);
}
}
}Modules§
- classifier
- Error classification and diagnostic generation for parsed Perl code. Error classification and diagnostic generation for Perl parsing workflows
- recovery
- Error recovery strategies and traits for the Perl parser. Error recovery for the Perl parser
Structs§
- Budget
Tracker - Tracks budget consumption during parsing.
- Error
Context - Rich error context with source line and fix suggestions
- Parse
Budget - Budget limits for parser operations to prevent runaway parsing.
- Parse
Output - Structured output from parsing, combining AST with all diagnostics.
Enums§
- Parse
Error - Comprehensive error types that can occur during Perl parsing workflows
- Recovery
Kind - What kind of recovery was applied at a
RecoverySite. - Recovery
Site - Where in the parse tree a recovery was performed.
Functions§
- get_
error_ contexts - Enrich a list of errors with source context
Type Aliases§
- Parse
Result - Result type for parser operations in the Perl parsing workflow pipeline