Skip to content

Instantly share code, notes, and snippets.

@sophiajt
Created February 25, 2016 21:35
Show Gist options
  • Save sophiajt/74de80d7566380d91308 to your computer and use it in GitHub Desktop.
Save sophiajt/74de80d7566380d91308 to your computer and use it in GitHub Desktop.
fn parse_if<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Stmt, ParseError> {
Ok(Stmt::Expr(Node::IntConst(3)))
}
fn parse_expr_stmt<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Stmt, ParseError> {
Ok(Stmt::Expr(Node::IntConst(4)))
}
fn parse_stmt<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Stmt, ParseError> {
let mut parser = match input.peek() {
Some(_) => parse_if,
_ => parse_expr_stmt
};
parser(input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment