use crate::{
define_error,
diagnostics::Builder,
lex::{Tok, TokenKind},
utils::{Located, Location},
};
pub struct UnexpectedEnd(pub Location);
define_error!(
UnexpectedEnd {
fn build(&self, builder: Builder) -> Builder {
builder.label(self.0.primary("reached the end of the file in the middle of parsing a statement"),)
}
fn location(&self) -> Location {
self.0
}
}
);
pub struct UnexpectedToken<K: TokenKind>(pub Tok<K>);
define_error!(
UnexpectedToken<K: TokenKind> {
fn build(&self, builder: Builder) -> Builder {
builder.label(self.0.primary(format!("'{}' is not valid in this position", self.0)))
}
fn location(&self) -> Location {
self.0.location()
}
}
);
pub struct ExpectedToken<K: TokenKind>(pub K, pub Location);
define_error!(
ExpectedToken<K: TokenKind> {
fn build(&self, builder: Builder) -> Builder {
builder.label(self.1.primary(format!("expected this to be '{}'", self.0)))
}
fn location(&self) -> Location {
self.1
}
}
);