pub struct Error {
pub kind: ErrorKind,
/* private fields */
}Expand description
Error type for parsing.
Fields§
§kind: ErrorKindKind of the error.
Implementations§
Source§impl Error
impl Error
Sourcepub fn upgrade<T>(&mut self, r: Result<T, Error>) -> Result<T, Error>
pub fn upgrade<T>(&mut self, r: Result<T, Error>) -> Result<T, Error>
Upgrade an error to one with greater pos value.
Sourcepub fn set_pos(&mut self, pos: impl TokenCount)
pub fn set_pos(&mut self, pos: impl TokenCount)
Set the position of the error.
Sometimes the position of the error is not known at the time of creation. This allows to adjust it later.
Sourcepub fn unexpected_token<T>(
at: Option<TokenTree>,
after: &TokenIter,
) -> Result<T, Error>
pub fn unexpected_token<T>( at: Option<TokenTree>, after: &TokenIter, ) -> Result<T, Error>
Create a Result<T>::Err(Error{ kind: ErrorKind::UnexpectedToken }) error at a token iter position.
Takes the failed token (if available) and a reference to the TokenIter past the error.
§Note on position tracking
The pos field is set to after.counter(), which represents the number of tokens
that were consumed up to and including the failed token (if any):
- If
atisSome(token): The token was consumed bynext()which incremented the counter, soposreflects the position AFTER consuming the failed token. - If
atisNone: The iterator was exhausted, soposreflects how many tokens were successfully consumed before running out.
Sourcepub fn unexpected_end<T>() -> Result<T, Error>
pub fn unexpected_end<T>() -> Result<T, Error>
Create a Result<T>::Err(Error{ kind: ErrorKind::UnexpectedToken }) error without a token iter.
Sourcepub fn out_of_range<const LIM: usize, T>(
have: usize,
at: Option<TokenTree>,
after: &TokenIter,
) -> Result<T, Error>
pub fn out_of_range<const LIM: usize, T>( have: usize, at: Option<TokenTree>, after: &TokenIter, ) -> Result<T, Error>
Create a Result<T>::Err(Error{ kind: ErrorKind::OutOfRange }) error at a token iter position.
Takes the failed token (if available) and a reference to the TokenIter past the error.
Sourcepub fn other<T>(
at: Option<TokenTree>,
after: &TokenIter,
reason: String,
) -> Result<T, Error>
pub fn other<T>( at: Option<TokenTree>, after: &TokenIter, reason: String, ) -> Result<T, Error>
Create a Result<T>::Err(Error{ kind: ErrorKind::Other }) error. Takes the failed
token (if available), a reference to the TokenIter past the error and a String
describing the error.
Sourcepub fn infinite_loop<T>(
at: Option<TokenTree>,
after: &TokenIter,
) -> Result<T, Error>
pub fn infinite_loop<T>( at: Option<TokenTree>, after: &TokenIter, ) -> Result<T, Error>
Create a Result<T>::Err(Error{ kind: ErrorKind::InfiniteLoop }) error. Used when a
repeating (conatianer) parser detects that the inner parser succeeded without
consuming any tokens, which would lead to an infinite loop.
Sourcepub fn dynamic<T>(
at: Option<TokenTree>,
after: &TokenIter,
error: impl Error + Send + Sync + 'static,
) -> Result<T, Error>
pub fn dynamic<T>( at: Option<TokenTree>, after: &TokenIter, error: impl Error + Send + Sync + 'static, ) -> Result<T, Error>
Create a Result<T>::Err(Error{ kind: ErrorKind::Dynamic }) error. Takes the failed
token (if available), a reference to the TokenIter past the error and a boxed error.
Sourcepub fn expected_type_name(&self) -> &'static str
pub fn expected_type_name(&self) -> &'static str
Returns the refined type name of the parser that failed.
Sourcepub const fn expected_original_type_name(&self) -> &'static str
pub const fn expected_original_type_name(&self) -> &'static str
Returns the original/fundamental type name of the parser that failed.
Sourcepub fn failed_at(&self) -> Option<TokenTree>
pub fn failed_at(&self) -> Option<TokenTree>
Returns a Option<TokenTree> where the error happend.
Sourcepub fn tokens_after(&self) -> TokenIter ⓘ
pub fn tokens_after(&self) -> TokenIter ⓘ
Returns a iterator to the tokens after the error
Creates a new TokenIter from the stored token stream position