We can now use our new combinator to define the rest of the `Expr`s. Starting with function application, we can see how the parser mirrors our data definitions: our definition is `Application(Box , Vec )`, so we know that we need to parse an expression and then parse 0 or more expressions, all wrapped in an S-expression. `tuple` is used to sequence parsers together, so we can translate
(i: &'a str)
| 235 | /// `tuple` is used to sequence parsers together, so we can translate this directly |
| 236 | /// and then map over it to transform the output into an `Expr::Application` |
| 237 | fn parse_application<'a>(i: &'a str) -> IResult<&'a str, Expr, VerboseError<&'a str>> { |
| 238 | let application_inner = map(tuple((parse_expr, many0(parse_expr))), |(head, tail)| { |
| 239 | Expr::Application(Box::new(head), tail) |
| 240 | }); |
| 241 | // finally, we wrap it in an s-expression |
| 242 | s_exp(application_inner)(i) |
| 243 | } |
| 244 | |
| 245 | /// Because `Expr::If` and `Expr::IfElse` are so similar (we easily could have |
| 246 | /// defined `Expr::If` to have an `Option` for the else block), we parse both |