Skip to main content

ParseError

Enum ParseError 

#[non_exhaustive]
pub enum ParseError { UnexpectedToken { token_type: CompactString, token_value: CompactString, line: Option<u32>, column: Option<u32>, pos_in_stream: Option<u32>, end_line: Option<u32>, end_column: Option<u32>, end_pos: Option<u32>, expected: Vec<String>, state: Option<u32>, }, UnexpectedCharacters { char_pos: u32, line: u32, column: u32, ch: char, allowed: Vec<String>, state: Option<u32>, }, Callback { message: String, }, Postlex { message: String, }, UnexpectedEOF { expected: Vec<String>, }, CustomLex { message: String, payload: Option<ForeignError>, }, Unsupported { message: String, }, Configuration { message: String, }, }
Expand description

Structured parse failure, mirroring Lark’s UnexpectedInput subclasses. $END rejection raises UnexpectedToken with the $END token exactly as Lark’s LALR does — UnexpectedEOF is Earley-only and the POC’s rewrite is a named parity bug we do not replicate.

#[non_exhaustive]: this enum has grown repeatedly (Postlex, CustomLex, Unsupported, Configuration all landed after the original set) and will again, so out-of-crate matches must carry a wildcard arm. Free to add before the first published release, permanently breaking after — same reasoning as Ambiguity.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

UnexpectedToken

Token (or synthetic $END) with no action in the current state. expected carries Lark’s precise accepts set (what its message shows): computed by callback-free trial feeds over a copy of the parser state, NOT the raw state-table row (which over-approximates and omits $END). Sorted.

Fields

§token_type: CompactString

The offending token; $END carries positions aliased from the last real token (corpus contract). All six positions ride along (Lark’s error token keeps its end_* trio too — with a custom source they are caller-supplied data).

§token_value: CompactString
§line: Option<u32>
§column: Option<u32>
§pos_in_stream: Option<u32>
§end_line: Option<u32>
§end_column: Option<u32>
§end_pos: Option<u32>
§expected: Vec<String>
§state: Option<u32>

The LALR parser state at the failure (ParserState::position()), for match_examples error classification. None for non-LALR origins / grammar-build synthesized errors. State ids are implementation-defined but consistent within a parser instance — the only property match_examples relies on.

§

UnexpectedCharacters

Lexer failure surfaced through the parse path (wraps LexError::UnexpectedCharacters; the allowed set here is the parser-context one where applicable, else the basic-lexer set).

Fields

§char_pos: u32
§line: u32
§column: u32
§ch: char
§allowed: Vec<String>
§state: Option<u32>

The LALR parser state at the lex failure (None for non-LALR origins). Companion to ParseError::UnexpectedToken’s state, for match_examples on a lexer-level error.

§

Callback

A user callback/transformer failed.

Fields

§message: String
§

Postlex

A postlex (indenter) session failed mid-stream — Lark’s DedentError (a LarkError), raised by the indent state machine on an unexpected dedent. Carries the verbatim message; the conformance runner surfaces it as the DedentError exception class (Lark canonicalizes it to just the class name — no position fields).

Fields

§message: String
§

UnexpectedEOF

Earley-only end-of-input failure (UnexpectedEOF): the whole input was consumed but no start-symbol derivation completed. This is genuine Earley behaviour (unrelated to the LALR $ENDUnexpectedToken path, which the POC’s UnexpectedEOF rewrite is a named parity bug for). expected carries the accepts set Lark shows.

Fields

§expected: Vec<String>
§

CustomLex

A custom crate::custom::TokenSource failed mid-pull with an arbitrary (non-lex-structured) error. payload is the opaque identity-preserving channel: in Lark, a custom lexer’s own exception escapes parse unwrapped, so a binding stores its host exception here and re-raises it by downcast. Message-only for pure-Rust sources. (Structured failures — CustomLexError::Lex — keep the built-in arms’ error classes instead.)

Fields

§message: String
§

Unsupported

A parse-time configuration reject Lark raises at parse() call time — the only member being on_error under a non-LALR parser, which Lark surfaces as a NotImplementedError. Kept out of the build-time crate::LarkBuildError channel because the offending kwarg (on_error) is a parse() argument, not a constructor one. Bindings map this to Python’s NotImplementedError (not an UnexpectedInput subclass).

Fields

§message: String
§

Configuration

A parse-time configuration reject Lark raises as ConfigurationError: an unknown start symbol, or start=None on a multi-start grammar (Lark’s _verify_start). Distinct from Self::Callback (a user reduce/postlex callback failure) so bindings surface the correct ConfigurationError class rather than a generic LarkError.

Fields

§message: String

Implementations§

§

impl ParseError

pub fn line(&self) -> Option<u32>

The 1-based line of the failure when the variant carries a position — ParseError::UnexpectedToken (still Option: a synthetic $END can be position-less) and ParseError::UnexpectedCharacters. None for the position-free variants (Callback / Postlex / UnexpectedEOF / …).

pub fn column(&self) -> Option<u32>

The 1-based column of the failure; see ParseError::line for which variants carry one.

pub fn pos_in_stream(&self) -> Option<u32>

The failure’s offset into the input in code points (Unicode scalar values — exactly Python len, the position contract these errors carry), when the variant has one. This is the index ParseError::get_context slices at.

pub fn get_context(&self, text: &str) -> String

A caret view of the failure site — the input line around the error with a ^ under the offending code point:

1 + * 2
    ^

This is Lark’s UnexpectedInput.get_context (span 40), ported verbatim, tab-expanded caret included. The parser retains no copy of the input, so the caller passes the original text back in; a position-free variant draws the caret at offset 0.

Trait Implementations§

§

impl Clone for ParseError

§

fn clone(&self) -> ParseError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for ParseError

§

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

Formats the value using the given formatter. Read more
§

impl Display for ParseError

§

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

Formats the value using the given formatter. Read more
§

impl Eq for ParseError

§

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
§

impl From<PostlexError> for ParseError

A configuration/stream error surfaces as ParseError::Postlex. Replaces the three copies of map_postlex_error the drivers used to carry.

§

fn from(e: PostlexError) -> Self

Converts to this type from the input type.
§

impl PartialEq for ParseError

§

fn eq(&self, other: &ParseError) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

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

§

impl<T> ToCompactString for T
where T: Display,

§

fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>

Fallible version of [ToCompactString::to_compact_string()] Read more
§

fn to_compact_string(&self) -> CompactString

Converts the given value to a [CompactString]. 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 = !

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.