pub enum RecoveryError {
Eof,
AlreadyRecovered,
RecoveryDisabled,
}Variants§
Eof
Recovery failed because the parser reached the end of file
AlreadyRecovered
Recovery failed because it didn’t eat any tokens. Meaning, the parser is already in a recovered state.
This is an error because:
a) It shouldn’t create a completed marker wrapping no tokens
b) This results in an infinite-loop if the recovery is used inside a while loop. For example,
it’s common that list parsing also recovers at the end of a statement or block. However, list elements
don’t start with a ; or } which is why parsing, for example, an array element fails again and
the array expression triggers another recovery. Handling this as an error ensures that list parsing
rules break out of the loop the same way as they would at the EOF.
RecoveryDisabled
Returned if there’s an unexpected token and the parser is speculatively parsing a syntax. Error-recovery is disabled when doing speculative parsing because it can then make the impression that the parser was able to correctly parse a syntax when, in fact, it only skipped over the tokens.
For example the syntax (a, b, c) ... in JavaScript can either be a parenthesized expression
or an arrow function, depending on what kind of token ... is. Thus, the parer’s only option is
to make the following assumption:
“Let’s assume (a, b, c) ...” is an arrow function expression“
The parser then tries to parse (a, b, c) as an arrow function parameters and validates that ...
indeed is the =>. The parser rewinds and re-parses the syntax as a parenthesized expression
if it turns out that ... isn’t the => token or if any element in (a, b, c) isn’t a valid parameter (for example 5 + 3 isn’t valid).
Trait Implementations§
Source§impl Debug for RecoveryError
impl Debug for RecoveryError
Source§impl Display for RecoveryError
impl Display for RecoveryError
Source§impl Error for RecoveryError
impl Error for RecoveryError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl PartialEq for RecoveryError
impl PartialEq for RecoveryError
impl Eq for RecoveryError
impl StructuralPartialEq for RecoveryError
Auto Trait Implementations§
impl Freeze for RecoveryError
impl RefUnwindSafe for RecoveryError
impl Send for RecoveryError
impl Sync for RecoveryError
impl Unpin for RecoveryError
impl UnwindSafe for RecoveryError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.