Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
261 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,113 @@ | ||
use num; | ||
use std; | ||
use trackable::error::TrackableError; | ||
use trackable::error::{ErrorKind as TrackableErrorKind, ErrorKindExt}; | ||
|
||
/// This crate specific error type. | ||
#[derive(Debug, Clone)] | ||
pub struct Error(TrackableError<ErrorKind>); | ||
derive_traits_for_trackable_error_newtype!(Error, ErrorKind); | ||
impl From<std::num::ParseIntError> for Error { | ||
fn from(f: std::num::ParseIntError) -> Self { | ||
ErrorKind::InvalidInput.cause(f).into() | ||
} | ||
use crate::Position; | ||
|
||
/// Possible errors. | ||
#[derive(Debug, thiserror::Error)] | ||
#[non_exhaustive] | ||
#[allow(missing_docs)] | ||
pub enum Error { | ||
/// No closing quotation. | ||
#[error("no closing quotation ({position})")] | ||
NoClosingQuotation { position: Position }, | ||
|
||
/// Invalid escaped character. | ||
#[error("cannnot parse a escaped character ({position})")] | ||
InvalidEscapedChar { position: Position }, | ||
|
||
/// A token was expected, but not found. | ||
#[error("a token was expected, but not found ({position})")] | ||
MissingToken { position: Position }, | ||
|
||
/// Unknown keyword. | ||
#[error("unknown keyword {keyword:?} ({position})")] | ||
UnknownKeyword { position: Position, keyword: String }, | ||
|
||
/// Invalid atom token. | ||
#[error("Canot parse an atom token ({position})")] | ||
InvalidAtomToken { position: Position }, | ||
|
||
/// Invalid character token. | ||
#[error("cannnot parse a character token ({position})")] | ||
InvalidCharToken { position: Position }, | ||
|
||
/// Invalid comment token. | ||
#[error("cannnot parse a comment token ({position})")] | ||
InvalidCommentToken { position: Position }, | ||
|
||
/// Invalid float token. | ||
#[error("cannnot parse a float token ({position})")] | ||
InvalidFloatToken { position: Position }, | ||
|
||
/// Invalid integer token. | ||
#[error("cannnot parse a integer token ({position})")] | ||
InvalidIntegerToken { position: Position }, | ||
|
||
/// Invalid string token. | ||
#[error("cannnot parse a string token ({position})")] | ||
InvalidStringToken { position: Position }, | ||
|
||
/// Invalid symbol token. | ||
#[error("cannnot parse a symbol token ({position})")] | ||
InvalidSymbolToken { position: Position }, | ||
|
||
/// Invalid variable token. | ||
#[error("cannnot parse a variable token ({position})")] | ||
InvalidVariableToken { position: Position }, | ||
|
||
/// Invalid whitespace token. | ||
#[error("cannnot parse a whitespace token ({position})")] | ||
InvalidWhitespaceToken { position: Position }, | ||
} | ||
impl From<std::num::ParseFloatError> for Error { | ||
fn from(f: std::num::ParseFloatError) -> Self { | ||
ErrorKind::InvalidInput.cause(f).into() | ||
|
||
impl Error { | ||
pub(crate) fn no_closing_quotation(position: Position) -> Self { | ||
Self::NoClosingQuotation { position } | ||
} | ||
} | ||
impl From<num::bigint::ParseBigIntError> for Error { | ||
fn from(f: num::bigint::ParseBigIntError) -> Self { | ||
ErrorKind::InvalidInput.cause(f).into() | ||
|
||
pub(crate) fn invalid_escaped_char(position: Position) -> Self { | ||
Self::InvalidEscapedChar { position } | ||
} | ||
} | ||
|
||
/// The list of the possible error kinds | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum ErrorKind { | ||
/// Input text is invalid. | ||
InvalidInput, | ||
pub(crate) fn missing_token(position: Position) -> Self { | ||
Self::MissingToken { position } | ||
} | ||
|
||
/// Unexpected End-Of-String. | ||
UnexpectedEos, | ||
} | ||
pub(crate) fn unknown_keyword(position: Position, keyword: String) -> Self { | ||
Self::UnknownKeyword { position, keyword } | ||
} | ||
|
||
pub(crate) fn invalid_atom_token(position: Position) -> Self { | ||
Self::InvalidAtomToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_char_token(position: Position) -> Self { | ||
Self::InvalidCharToken { position } | ||
} | ||
|
||
impl TrackableErrorKind for ErrorKind {} | ||
pub(crate) fn invalid_comment_token(position: Position) -> Self { | ||
Self::InvalidCommentToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_float_token(position: Position) -> Self { | ||
Self::InvalidFloatToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_integer_token(position: Position) -> Self { | ||
Self::InvalidIntegerToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_string_token(position: Position) -> Self { | ||
Self::InvalidStringToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_symbol_token(position: Position) -> Self { | ||
Self::InvalidSymbolToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_variable_token(position: Position) -> Self { | ||
Self::InvalidVariableToken { position } | ||
} | ||
|
||
pub(crate) fn invalid_whitespace_token(position: Position) -> Self { | ||
Self::InvalidWhitespaceToken { position } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.