58 lines
1.7 KiB
Rust
58 lines
1.7 KiB
Rust
|
use std::fmt;
|
||
|
use token::{PartialToken, Token};
|
||
|
|
||
|
impl fmt::Display for Token {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||
|
use self::Token::*;
|
||
|
match self {
|
||
|
Plus => write!(f, "+"),
|
||
|
Minus => write!(f, "-"),
|
||
|
Star => write!(f, "*"),
|
||
|
Slash => write!(f, "/"),
|
||
|
Percent => write!(f, "%"),
|
||
|
Hat => write!(f, "^"),
|
||
|
|
||
|
// Logic
|
||
|
Eq => write!(f, "=="),
|
||
|
Neq => write!(f, "!="),
|
||
|
Gt => write!(f, ">"),
|
||
|
Lt => write!(f, "<"),
|
||
|
Geq => write!(f, ">="),
|
||
|
Leq => write!(f, "<="),
|
||
|
And => write!(f, "&&"),
|
||
|
Or => write!(f, "||"),
|
||
|
Not => write!(f, "!"),
|
||
|
|
||
|
// Precedence
|
||
|
LBrace => write!(f, "("),
|
||
|
RBrace => write!(f, ")"),
|
||
|
|
||
|
// Aggregation
|
||
|
Comma => write!(f, ","),
|
||
|
|
||
|
// Values => write!(f, ""), Variables and Functions
|
||
|
Identifier(identifier) => identifier.fmt(f),
|
||
|
Float(float) => float.fmt(f),
|
||
|
Int(int) => int.fmt(f),
|
||
|
Boolean(boolean) => boolean.fmt(f),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl fmt::Display for PartialToken {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||
|
use self::PartialToken::*;
|
||
|
match self {
|
||
|
Token(token) => token.fmt(f),
|
||
|
Literal(literal) => literal.fmt(f),
|
||
|
Whitespace => write!(f, " "),
|
||
|
Eq => write!(f, "="),
|
||
|
ExclamationMark => write!(f, "!"),
|
||
|
Gt => write!(f, ">"),
|
||
|
Lt => write!(f, "<"),
|
||
|
Ampersand => write!(f, "&"),
|
||
|
VerticalBar => write!(f, "|"),
|
||
|
}
|
||
|
}
|
||
|
}
|