Created
April 4, 2014 04:28
-
-
Save swgillespie/9968150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// A LashToken is a token in Lash. Every token has an associated value. | |
/// | |
use std::io; | |
use std::result; | |
pub enum LashToken { | |
Identifier(~str), | |
Integer(i32), | |
Float(f64), | |
StringLiteral(~str), | |
LParen, | |
RParen, | |
LBracket, | |
RBracket, | |
LBrace, | |
RBrace, | |
Dot, | |
Comma, | |
Operator(~str), | |
Let, | |
For, | |
In, | |
If, | |
Else, | |
Unless, | |
Throw, | |
Catch, | |
As, | |
Func, | |
Nil, | |
False, | |
True, | |
Using, | |
From, | |
Try, | |
Rethrow, | |
Finally | |
} | |
pub struct LashLexer<'a> { | |
input_stream: &'a io::Reader, | |
unget_stack : ~[u8], | |
tokens : ~[LashToken] | |
} | |
impl<'a> LashLexer<'a> { | |
pub fn new(mut input: &'a mut io::Reader) -> ~LashLexer { | |
~LashLexer{ | |
input_stream: input, | |
unget_stack: ~[], | |
tokens: ~[] | |
} | |
} | |
fn get_u8(&mut self) -> Result<u8, io::IoError> { | |
match self.unget_stack.pop() { | |
Some(u8) => Ok(u8), | |
None => self.input_stream.read_byte(), | |
} | |
} | |
fn unget_u8(&mut self, unget_char: u8) { | |
self.unget_stack.push(unget_char); | |
} | |
} | |
fn main() { | |
println!("Hello world!"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment