diff options
author | Graham Northup <grissess@nexusg.org> | 2017-09-24 03:41:45 -0400 |
---|---|---|
committer | Graham Northup <grissess@nexusg.org> | 2017-09-24 03:41:45 -0400 |
commit | 7eef21b3b90898f4ef05fa4220fde608cf55c6ab (patch) | |
tree | db09a752bef57a5b6eb6040048ed1fdf66ab5043 /src/lang/mod.rs | |
parent | 3d370b9a980d88f884ddd87b62bc785c3b963e1d (diff) |
parser appears to work (oh my)
Diffstat (limited to 'src/lang/mod.rs')
-rw-r--r-- | src/lang/mod.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lang/mod.rs b/src/lang/mod.rs index 8256f34..14a9202 100644 --- a/src/lang/mod.rs +++ b/src/lang/mod.rs @@ -1,6 +1,10 @@ pub mod tokenizer; pub use self::tokenizer::Tokenizer; +pub mod parser; +pub use self::parser::Parser; +// NB: No Eq due to embedded f32 +#[derive(Debug,PartialEq,Clone)] pub enum Token { Ident(String), Integer(isize), @@ -10,3 +14,31 @@ pub enum Token { EOF, } +#[derive(Debug,PartialEq,Eq,Clone,Copy)] +pub enum TokType { + Ident, + Integer, + Float, + Oper, + String, + EOF, +} + +impl Token { + pub fn to_type(&self) -> TokType { + match *self { + Token::Ident(_) => TokType::Ident, + Token::Integer(_) => TokType::Integer, + Token::Float(_) => TokType::Float, + Token::Oper(_) => TokType::Oper, + Token::String(_) => TokType::String, + Token::EOF => TokType::EOF, + } + } +} + +impl<'a> From<&'a Token> for TokType { + fn from(tok: &'a Token) -> TokType { + tok.to_type() + } +} |