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: SiteRefSpanA span of tokens where the error occurred.
context: NodeRuleA parsing rule that reported the error.
recovery: RecoveryResultA type of the recovery strategy that has been applied.
expected_tokens: &'static TokenSetA set of tokens that the parser expected in the span.
expected_nodes: &'static NodeSetA set of nodes that the parser expected in the span.
Implementations§
Source§impl SyntaxError
impl SyntaxError
Sourcepub fn title<N: AbstractNode>(&self) -> impl Display + '_
pub fn title<N: AbstractNode>(&self) -> impl Display + '_
Returns a displayable object that prints a canonical title of this syntax error.
Sourcepub fn message<N: Node>(
&self,
code: &impl SourceCode<Token = <N as Node>::Token>,
) -> impl Debug + Display + '_
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.
Sourcepub fn display<'a>(
&'a self,
unit: &'a impl CompilationUnit,
) -> impl Debug + Display + 'a
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.
Sourcepub fn aligned_span(&self, code: &impl SourceCode) -> SiteRefSpan
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
impl Clone for SyntaxError
Source§fn clone(&self) -> SyntaxError
fn clone(&self) -> SyntaxError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more