parent
5e491f6771
commit
16bde54aa5
57
src/token/display.rs
Normal file
57
src/token/display.rs
Normal file
@ -0,0 +1,57 @@
|
||||
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, "|"),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
use error::Error;
|
||||
use value::{FloatType, IntType};
|
||||
|
||||
mod display;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Token {
|
||||
// Arithmetic
|
||||
|
Loading…
Reference in New Issue
Block a user