use ecma_lex_cat::error::Error as LexError;
use ecma_syntax_cat::error::Error as SyntaxError;
use ecma_syntax_cat::span::Span;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Lex(LexError),
Syntax(SyntaxError),
UnexpectedToken {
at: Span,
expected: &'static str,
found: String,
},
UnexpectedEof {
expected: &'static str,
},
InvalidAssignmentTarget {
at: Span,
},
InvalidArrowParameter {
at: Span,
},
InvalidClassMember {
at: Span,
},
}
impl From<LexError> for Error {
fn from(value: LexError) -> Self {
Self::Lex(value)
}
}
impl From<SyntaxError> for Error {
fn from(value: SyntaxError) -> Self {
Self::Syntax(value)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Lex(e) => write!(f, "lex error: {e}"),
Self::Syntax(e) => write!(f, "syntax error: {e}"),
Self::UnexpectedToken {
at,
expected,
found,
} => write!(f, "{at}: unexpected token {found:?}; expected {expected}"),
Self::UnexpectedEof { expected } => {
write!(f, "unexpected end of input; expected {expected}")
}
Self::InvalidAssignmentTarget { at } => {
write!(f, "{at}: not a valid assignment target")
}
Self::InvalidArrowParameter { at } => {
write!(f, "{at}: not a valid arrow parameter")
}
Self::InvalidClassMember { at } => {
write!(f, "{at}: not a valid class member")
}
}
}
}
impl std::error::Error for Error {}