Skip to main content

FullyErrorTolerantParser

Trait FullyErrorTolerantParser 

Source
pub trait FullyErrorTolerantParser<'ast, T> {
    // Required method
    fn parse_fully_tolerant<'input>(
        &self,
        alloc: &'ast AstAlloc,
        file_id: FileId,
        lexer: impl Iterator<Item = Result<SpannedToken<'input>, LexicalError>>,
        full_span: RawSpan,
    ) -> (T, ParseErrors);
}
Expand description

Additional capabilities for parsers that return Asts, offering an error-tolerant interface that is actually infallible.

The interface of error tolerant parsers is a bit strange: albeit dubbed as error-tolerant, ErrorTolerantParser::parse_tolerant is still fallible with the same error type that is returned in the Ok case. There are thus some parse errors that are fatal: the issue is that LALRPOP can’t generate a proper AST when it can’t even get to complete one parsing rule, in which case it bails out. But this is artificial, because we can still produce an AST with one node spanning the full file, this node being the fatal error.

This is precisely what does FullyErrorTolerantParser, which wraps ErrorTolerantParser when T is Ast<'ast>.

Required Methods§

Source

fn parse_fully_tolerant<'input>( &self, alloc: &'ast AstAlloc, file_id: FileId, lexer: impl Iterator<Item = Result<SpannedToken<'input>, LexicalError>>, full_span: RawSpan, ) -> (T, ParseErrors)

Parse a value from a lexer with the given file_id in an error-tolerant way.

When the parser fails without being able to produce a proper AST, we need to construct the root as the error node. Since this isn’t easy to reverse-engineer the whole span of the original file from the lexer, we take it as an explicit argument.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'ast, P> FullyErrorTolerantParser<'ast, Ast<'ast>> for P
where P: ErrorTolerantParser<'ast, Ast<'ast>>,