MCPcopy Create free account
hub / github.com/chc4/lineiform / parse_application

Function parse_application

src/parser.rs:237–243  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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`
237fn 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

Callers

nothing calls this directly

Calls 1

s_expFunction · 0.85

Tested by

no test coverage detected