SyntaxError

Struct SyntaxError 

Source
pub struct SyntaxError {
    pub span: SiteRefSpan,
    pub context: NodeRule,
    pub recovery: RecoveryResult,
    pub expected_tokens: &'static TokenSet,
    pub expected_nodes: &'static NodeSet,
}
Expand description

A syntax error that may occur during the parsing process.

In Lady Deirdre syntax parsing is an infallible process. Hence, the syntax error object represents a report of the parser’s error recovery attempt.

Fields§

§span: SiteRefSpan

A span of tokens where the error occurred.

§context: NodeRule

A parsing rule that reported the error.

§recovery: RecoveryResult

A type of the recovery strategy that has been applied.

§expected_tokens: &'static TokenSet

A set of tokens that the parser expected in the span.

§expected_nodes: &'static NodeSet

A set of nodes that the parser expected in the span.

Implementations§

Source§

impl SyntaxError

Source

pub fn title<N: AbstractNode>(&self) -> impl Display + '_

Returns a displayable object that prints a canonical title of this syntax error.

Source

pub fn message<N: Node>( &self, code: &impl SourceCode<Token = <N as Node>::Token>, ) -> impl Debug + Display + '_

Returns a displayable object that prints a canonical message of this syntax error.

The code parameter provides access to the compilation unit’s tokens of where the error occurred.

Source

pub fn display<'a>( &'a self, unit: &'a impl CompilationUnit, ) -> impl Debug + Display + 'a

Returns a displayable object that prints a Snippet that annotates the source code span with an error message.

The unit parameter provides access to the compilation unit of where the error occurred.

Source

pub fn aligned_span(&self, code: &impl SourceCode) -> SiteRefSpan

Computes a token span from the syntax error’s original span such that the new span would be properly aligned in regards to the whitespaces and the line breaks surrounding the original span.

The code parameter provides access to the compilation unit’s tokens of where the error occurred.

The exact details of the underlying algorithm are not specified, and the algorithm is subject to improvements over time in the minor versions of this crate, but the function attempts to generate a span that would better fit for the end-user facing rather than the original machine-generated span.

Trait Implementations§

Source§

impl Clone for SyntaxError

Source§

fn clone(&self) -> SyntaxError

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 SyntaxError

Source§

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

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

impl PartialEq for SyntaxError

Source§

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

Source§

impl StructuralPartialEq for SyntaxError

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.

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