Add Display trait to Token and Kind
This commit is contained in:
parent
79080ff62b
commit
9561e1bf91
1 changed files with 19 additions and 0 deletions
19
src/lexer.rs
19
src/lexer.rs
|
@ -1,5 +1,7 @@
|
||||||
//! # Lexer
|
//! # Lexer
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use characters;
|
use characters;
|
||||||
use characters::RelativeIndexable;
|
use characters::RelativeIndexable;
|
||||||
|
|
||||||
|
@ -9,11 +11,28 @@ pub enum Kind {
|
||||||
Identifier,
|
Identifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Kind {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let s = match *self {
|
||||||
|
Kind::LeftParen => "LeftParen",
|
||||||
|
Kind::RightParen => "RightParen",
|
||||||
|
Kind::Identifier => "Identifier",
|
||||||
|
};
|
||||||
|
write!(f, "{}", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Token {
|
pub struct Token {
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
value: String,
|
value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Token {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "({}, \"{}\")", self.kind, self.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
Initial,
|
Initial,
|
||||||
Identifier,
|
Identifier,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue