Skip to main content

Crate perl_error

Crate perl_error 

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

  1. Parse stage: Parsing failures indicate corrupted or malformed Perl source
  2. Analyze stage: Syntax errors suggest script inconsistencies requiring fallback processing
  3. Navigate stage: Parse failures can break thread analysis - graceful degradation applies
  4. Complete stage: Errors impact output generation but preserve original content
  5. 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§

BudgetTracker
Tracks budget consumption during parsing.
ErrorContext
Rich error context with source line and fix suggestions
ParseBudget
Budget limits for parser operations to prevent runaway parsing.
ParseOutput
Structured output from parsing, combining AST with all diagnostics.

Enums§

ParseError
Comprehensive error types that can occur during Perl parsing workflows
RecoveryKind
What kind of recovery was applied at a RecoverySite.
RecoverySite
Where in the parse tree a recovery was performed.

Functions§

get_error_contexts
Enrich a list of errors with source context

Type Aliases§

ParseResult
Result type for parser operations in the Perl parsing workflow pipeline