type alias for Tokens
This commit is contained in:
parent
67eafba97a
commit
cea29094cd
@ -17,9 +17,10 @@ pub enum ParseResult {
|
|||||||
Err(String)
|
Err(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Tokens<'a> = Iter<'a,Token>;
|
||||||
|
|
||||||
macro_rules! expect {
|
macro_rules! expect {
|
||||||
($tok:expr, $tokens:expr) => ( if !expect_token($tok, $tokens) {
|
($tok:expr, $tokens:expr) => ( if !expect_token($tok, $tokens) {
|
||||||
println!("yo hitting");
|
|
||||||
return ParseResult::Err(format!("Expected {:?}", $tok));
|
return ParseResult::Err(format!("Expected {:?}", $tok));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -36,7 +37,7 @@ pub fn parse(input: Vec<Token>) -> ParseResult {
|
|||||||
return ParseResult::Err("Bad parse".to_string());
|
return ParseResult::Err("Bad parse".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect_token(tok: Token, tokens: &mut Iter<Token>) -> bool {
|
fn expect_token(tok: Token, tokens: &mut Tokens) -> bool {
|
||||||
if let Some(n) = tokens.next() {
|
if let Some(n) = tokens.next() {
|
||||||
let next = (*n).clone();
|
let next = (*n).clone();
|
||||||
return match (tok, next) {
|
return match (tok, next) {
|
||||||
@ -55,7 +56,7 @@ fn expect_token(tok: Token, tokens: &mut Iter<Token>) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn let_expression<'a>(input: &mut Iter<Token>) -> ParseResult {
|
fn let_expression(input: &mut Tokens) -> ParseResult {
|
||||||
expect!(Identifier("let".to_string()), input);
|
expect!(Identifier("let".to_string()), input);
|
||||||
if let Some(&Identifier(ref name)) = input.next() {
|
if let Some(&Identifier(ref name)) = input.next() {
|
||||||
if let Some(&Identifier(ref s)) = input.next() {
|
if let Some(&Identifier(ref s)) = input.next() {
|
||||||
|
Loading…
Reference in New Issue
Block a user