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); };
loop {
let lookahead = tokens.peek().map(|i| i.clone()); statements.push(initial_statement);
if let Some(&Separator) = lookahead {
tokens.next(); loop {
if let ParseResult::Ok(ast_next) = statement(tokens) { let lookahead = tokens.peek().map(|i| i.clone());
match lookahead {
Some(&Separator) => {
tokens.next();
match statement(tokens) {
ParseResult::Ok(ast_next) => {
statements.push(ast_next); statements.push(ast_next);
} else { },
return ParseResult::Err("bad thing happened".to_string()); err@ParseResult::Err(_) => return err
} };
} else { },
break; _ => break
}
}
},
err@ParseResult::Err(_) => {
return err;
} }
} }