Skip to main content

ParseError

Enum ParseError 

Source
pub enum ParseError {
    UnexpectedEof,
    UnexpectedToken {
        expected: String,
        found: String,
        location: usize,
    },
    SyntaxError {
        message: String,
        location: usize,
    },
    LexerError {
        message: String,
    },
    RecursionLimit,
    InvalidNumber {
        literal: String,
    },
    InvalidString,
    UnclosedDelimiter {
        delimiter: char,
    },
    InvalidRegex {
        message: String,
    },
    NestingTooDeep {
        depth: usize,
        max_depth: usize,
    },
    Cancelled,
    Recovered {
        site: RecoverySite,
        kind: RecoveryKind,
        location: usize,
    },
}
Expand description

Parse error and result types for parser output. Comprehensive error types that can occur during Perl parsing workflows

These errors are designed to provide detailed context about parsing failures that occur during Perl code analysis, script processing, and metadata extraction. Each error variant includes location information to enable precise recovery strategies in large Perl file processing scenarios.

§Error Recovery Patterns

  • Syntax Errors: Attempt fallback parsing or skip problematic content sections
  • Lexer Errors: Re-tokenize with relaxed rules or binary content detection
  • Recursion Limits: Flatten deeply nested structures or process iteratively
  • String Handling: Apply encoding detection and normalization workflows

§Enterprise Scale Considerations

Error handling is optimized for large Perl files and multi-file workspaces, ensuring memory-efficient error propagation and logging.

Variants§

§

UnexpectedEof

Parser encountered unexpected end of input during Perl code analysis

This occurs when processing truncated Perl scripts or incomplete Perl source during the Parse stage. Recovery strategy: attempt partial parsing and preserve available content.

§

UnexpectedToken

Parser found an unexpected token during Perl parsing workflow

Common during Analyze stage when Perl scripts contain syntax variations or encoding issues. Recovery strategy: skip problematic tokens and attempt continued parsing with relaxed rules.

Fields

§expected: String

Token type that was expected during Perl script parsing

§found: String

Actual token found in Perl script content

§location: usize

Byte position where unexpected token was encountered

§

SyntaxError

General syntax error occurred during Perl code parsing

This encompasses malformed Perl constructs found in Perl scripts during Navigate stage analysis. Recovery strategy: isolate syntax error scope and continue processing surrounding content.

Fields

§message: String

Descriptive error message explaining the syntax issue

§location: usize

Byte position where syntax error occurred in Perl script

§

LexerError

Lexical analysis failure during Perl script tokenization

Indicates character encoding issues or binary content mixed with text during Parse stage. Recovery strategy: apply encoding detection and re-attempt tokenization with binary fallbacks.

Fields

§message: String

Detailed lexer error message describing tokenization failure

§

RecursionLimit

Parser recursion depth exceeded during complex Perl script analysis

Occurs with deeply nested structures in Perl code during Complete stage processing. Recovery strategy: flatten recursive structures and process iteratively to maintain performance.

§

InvalidNumber

Invalid numeric literal found in Perl script content

Common when processing malformed configuration values during Analyze stage analysis. Recovery strategy: substitute default values and log for manual review.

Fields

§literal: String

The malformed numeric literal found in Perl script content

§

InvalidString

Malformed string literal in Perl parsing workflow

Indicates quote mismatches or encoding issues in Perl script strings during parsing. Recovery strategy: attempt string repair and normalization before re-parsing.

§

UnclosedDelimiter

Unclosed delimiter detected during Perl code parsing

Commonly found in truncated or corrupted Perl script content during Parse stage. Recovery strategy: auto-close delimiters and continue parsing with synthetic boundaries.

Fields

§delimiter: char

The delimiter character that was left unclosed

§

InvalidRegex

Invalid regular expression syntax in Perl parsing workflow

Occurs when parsing regex patterns in data filters during Navigate stage analysis. Recovery strategy: fallback to literal string matching and preserve original pattern.

Fields

§message: String

Specific error message describing regex syntax issue

§

NestingTooDeep

Nesting depth limit exceeded for recursive structures

Fields

§depth: usize

Current nesting depth

§max_depth: usize

Maximum allowed depth

§

Cancelled

Parsing was cancelled by an external cancellation token

§

Recovered

A syntax error was recovered from — parsing continued with a synthetic node.

This variant is emitted alongside the partial AST node that was produced by the recovery. LSP providers iterate parser.errors() and count Recovered variants to determine confidence for gating features.

Fields

§site: RecoverySite

Where in the parse tree the recovery occurred.

§kind: RecoveryKind

What kind of repair was applied.

§location: usize

Byte offset of the recovery point in the source.

Implementations§

Source§

impl ParseError

Source

pub fn syntax(message: impl Into<String>, location: usize) -> ParseError

Create a new syntax error for Perl parsing workflow failures

§Arguments
  • message - Descriptive error message with context about the syntax issue
  • location - Character position within the Perl code where error occurred
§Returns

A ParseError::SyntaxError variant with embedded location context for recovery strategies

§Examples
use perl_error::ParseError;

let error = ParseError::syntax("Missing semicolon in Perl script", 42);
assert!(matches!(error, ParseError::SyntaxError { .. }));
Source

pub fn unexpected( expected: impl Into<String>, found: impl Into<String>, location: usize, ) -> ParseError

Create a new unexpected token error during Perl script parsing

§Arguments
  • expected - Token type that was expected by the parser
  • found - Actual token type that was encountered
  • location - Character position where the unexpected token was found
§Returns

A ParseError::UnexpectedToken variant with detailed token mismatch information

§Examples
use perl_error::ParseError;

let error = ParseError::unexpected("semicolon", "comma", 15);
assert!(matches!(error, ParseError::UnexpectedToken { .. }));
§Email Processing Context

This is commonly used during the Analyze stage when Perl scripts contain syntax variations that require token-level recovery strategies.

Source

pub fn location(&self) -> Option<usize>

Get the byte location of the error if available

Source

pub fn suggestion(&self) -> Option<String>

Generate a fix suggestion based on the error type

Trait Implementations§

Source§

impl Clone for ParseError

Source§

fn clone(&self) -> ParseError

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 ParseError

Source§

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

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

impl Display for ParseError

Source§

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

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

impl Error for ParseError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<RegexError> for ParseError

Source§

fn from(err: RegexError) -> ParseError

Converts to this type from the input type.
Source§

impl PartialEq for ParseError

Source§

fn eq(&self, other: &ParseError) -> 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 ParseError

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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