Skip to main content

ParseError

Enum ParseError 

Source
pub enum ParseError {
    Located {
        line: usize,
        column: usize,
        position: usize,
        message: String,
        hint: Option<String>,
    },
    UnexpectedToken {
        position: usize,
        expected: String,
        found: String,
    },
    UnexpectedEof,
    InvalidToken {
        position: usize,
        message: String,
    },
    InvalidNumber(String),
    InvalidDuration(String),
    InvalidTimestamp(String),
    UnterminatedString(usize),
    InvalidEscape(String),
    Custom {
        span: Span,
        message: String,
    },
}
Expand description

Errors that can occur during VPL parsing.

Variants§

§

Located

Error with precise source location and an optional hint for the user.

Fields

§line: usize

1-based line number where the error occurred.

§column: usize

1-based column number where the error occurred.

§position: usize

0-based byte offset in the source string.

§message: String

Human-readable description of the error.

§hint: Option<String>

Optional suggestion for how to fix the error.

§

UnexpectedToken

An unexpected token was encountered during parsing.

Fields

§position: usize

0-based byte offset of the unexpected token.

§expected: String

Description of what was expected.

§found: String

Description of what was found instead.

§

UnexpectedEof

The input ended unexpectedly (e.g., unclosed parenthesis).

§

InvalidToken

A token that does not belong to the VPL grammar was found.

Fields

§position: usize

0-based byte offset of the invalid token.

§message: String

Description of why the token is invalid.

§

InvalidNumber(String)

A numeric literal could not be parsed.

§

InvalidDuration(String)

A duration literal (e.g., 5s, 100ms) could not be parsed.

§

InvalidTimestamp(String)

A timestamp literal (e.g., @2024-01-15) could not be parsed.

§

UnterminatedString(usize)

A string literal was not closed before end of input.

Tuple Fields

§0: usize

0-based byte offset where the string started.

§

InvalidEscape(String)

An unrecognized escape sequence was found inside a string literal.

§

Custom

A custom error with an associated source span.

Fields

§span: Span

Source span where the error occurred.

§message: String

Human-readable error message.

Implementations§

Source§

impl ParseError

Source

pub fn custom(span: Span, message: impl Into<String>) -> Self

Create a custom error from a source span and message.

Source

pub fn at_location( source: &str, position: usize, message: impl Into<String>, hint: Option<String>, ) -> Self

Create an error with source location and optional hint

Source

pub fn source_span(&self, source: &str) -> (usize, usize)

Extract the byte offset and length for highlighting in the source.

Returns (offset, length) where length defaults to 1 when only a point position is available.

Source

pub fn hint(&self) -> Option<&str>

Return the hint text, if the variant carries one.

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

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

impl Display for ParseError

Source§

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

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

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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