Simplified statements-parsing

Still a little wonky wrt extraneous Separators, need to adjust grammar
to fix I think
This commit is contained in:
greg 2015-07-25 16:55:58 -07:00
parent 30eddf7737
commit c9fdd5e83c

View File

@ -71,26 +71,26 @@ fn statements(tokens: &mut Tokens) -> ParseResult {
let mut statements = Vec::new(); let mut statements = Vec::new();
let initial_statement = statement(tokens); let initial_statement = match statement(tokens) {
match initial_statement { err@ParseResult::Err(_) => return err,
ParseResult::Ok(ast) => { ParseResult::Ok(ast) => ast
statements.push(ast); };
statements.push(initial_statement);
loop { loop {
let lookahead = tokens.peek().map(|i| i.clone()); let lookahead = tokens.peek().map(|i| i.clone());
if let Some(&Separator) = lookahead { match lookahead {
Some(&Separator) => {
tokens.next(); tokens.next();
if let ParseResult::Ok(ast_next) = statement(tokens) { match statement(tokens) {
ParseResult::Ok(ast_next) => {
statements.push(ast_next); statements.push(ast_next);
} else {
return ParseResult::Err("bad thing happened".to_string());
}
} else {
break;
}
}
}, },
err@ParseResult::Err(_) => { err@ParseResult::Err(_) => return err
return err; };
},
_ => break
} }
} }