#[derive(Debug, PartialEq, Clone)]
pub enum Token {
Illegal,
Eof,
Name { name: String }, DotIdent { name: String }, Ident { name: String }, Int { decoded: i64 }, Float { decoded: f64 }, String { decoded: String }, Bytes { decoded: Vec<u8> }, Timestamp { nanos: i64 }, Duration { nanos: i64 },
Semi, Package, Decl, Use, Bound, Descr, Inclusion, Let, Do, LParen, RParen, LBracket, RBracket, LBrace, RBrace, Colon, ColonDash, Eq, Bang, BangEq, Comma, Lt, Le, Gt, Ge, Pipe, PipeGt, Dot, At, LongLeftDoubleArrow, }
impl std::fmt::Display for Token {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
macro_rules! token_text {
( $fstr:expr ) => {
write!(f, $fstr)
};
( $fstr:expr, $( $x:expr ),* ) => {
write!(f, $fstr, ($($x),+))
};
}
match self {
Token::Illegal => token_text!["illegal"],
Token::Eof => token_text!["eof"],
Token::Package => token_text!["Package"],
Token::Decl => token_text!["Decl"],
Token::Name { name } => token_text!["{}", name],
Token::DotIdent { name } => token_text![".{}", name],
Token::Ident { name } => token_text!["{}", name],
Token::Int { decoded } => token_text!["{}", decoded],
Token::Float { decoded } => token_text!["{}", decoded],
Token::String { decoded } => token_text!["{}", crate::quote::quote(decoded.as_str())],
Token::Bytes { decoded } => token_text!["{:?}", decoded],
Token::Timestamp { nanos } => token_text!["timestamp({})", nanos],
Token::Duration { nanos } => token_text!["duration({})", nanos],
Token::Semi => token_text![";"],
Token::Use => token_text!["Use"],
Token::LParen => token_text!["("],
Token::RParen => token_text![")"],
Token::LBrace => token_text!["{{"],
Token::RBrace => token_text!["}}"],
Token::Colon => token_text![":"],
Token::ColonDash => token_text![":-"],
Token::Pipe => token_text!["|"],
Token::PipeGt => token_text!["|>"],
Token::Bound => token_text!["bound"],
Token::Inclusion => token_text!["inclusion"],
Token::Descr => token_text!["descr"],
Token::Let => token_text!["let"],
Token::Do => token_text!["do"],
Token::LBracket => token_text!["["],
Token::RBracket => token_text!["]"],
Token::Eq => token_text!["="],
Token::Bang => token_text!["!"],
Token::BangEq => token_text!["!="],
Token::Comma => token_text![","],
Token::Lt => token_text!["<"],
Token::Le => token_text!["<="],
Token::Gt => token_text![">"],
Token::Ge => token_text!["<="],
Token::Dot => token_text!["."],
Token::At => token_text!["@"],
Token::LongLeftDoubleArrow => token_text!["⟸"],
}
}
}