diff options
Diffstat (limited to 'dhall/src')
-rw-r--r-- | dhall/src/core.rs | 14 | ||||
-rw-r--r-- | dhall/src/grammar.lalrpop | 2 | ||||
-rw-r--r-- | dhall/src/parser.rs | 21 |
3 files changed, 22 insertions, 15 deletions
diff --git a/dhall/src/core.rs b/dhall/src/core.rs index 88eff36..5b82160 100644 --- a/dhall/src/core.rs +++ b/dhall/src/core.rs @@ -169,6 +169,14 @@ pub enum Expr<'i, S, A> { UnionLit(&'i str, Box<Expr<'i, S, A>>, BTreeMap<&'i str, Expr<'i, S, A>>), /// `Combine x y ~ x ∧ y` Combine(Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>), + /// x //\\ y + CombineTypes(Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>), + /// x ? y + ImportAlt(Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>), + /// x // y + Prefer(Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>), + /// x # y + ListAppend(Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>), /// `Merge x y t ~ merge x y : t` Merge(Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>, Box<Expr<'i, S, A>>), /// `Field e x ~ e.x` @@ -696,7 +704,7 @@ pub fn shift<'i, S, T, A: Clone>(d: isize, v: V, e: &Expr<'i, S, A>) -> Expr<'i, // The Dhall compiler enforces that all embedded values are closed expressions // and `shift` does nothing to a closed expression Embed(ref p) => Embed(p.clone()), - FailedParse(_, _) => unreachable!(), + _ => panic!(), } } @@ -793,7 +801,7 @@ pub fn subst<'i, S, T, A>(v: V<'i>, e: &Expr<'i, S, A>, b: &Expr<'i, T, A>) -> E Field(ref a, b) => Field(bx(subst(v, e, a)), b), Note(_, ref b) => subst(v, e, b), Embed(ref p) => Embed(p.clone()), - FailedParse(_, _) => unreachable!(), + _ => panic!(), } } @@ -1038,7 +1046,7 @@ pub fn normalize<'i, S, T, A>(e: &Expr<'i, S, A>) -> Expr<'i, T, A> }, Note(_, ref e) => normalize(e), Embed(ref a) => Embed(a.clone()), - FailedParse(_, _) => unreachable!(), + _ => panic!(), } } diff --git a/dhall/src/grammar.lalrpop b/dhall/src/grammar.lalrpop index 250a45e..1d832b7 100644 --- a/dhall/src/grammar.lalrpop +++ b/dhall/src/grammar.lalrpop @@ -58,7 +58,6 @@ extern { } pub Expr: BoxExpr<'input> = { // exprA - <ExprB> ":" <Expr> => bx(Annot(<>)), ExprB, }; @@ -69,6 +68,7 @@ ExprB: BoxExpr<'input> = { <ExprC> "->" <ExprB> => bx(Pi("_", <>)), Let <Label> <(":" <Expr>)?> "=" <Expr> In <ExprB> => bx(Let(<>)), "[" <a:Elems> "]" ":" <b:ListLike> <c:ExprE> => bx(b(c, a)), + <ExprC> ":" <Expr> => bx(Annot(<>)), ExprC, }; diff --git a/dhall/src/parser.rs b/dhall/src/parser.rs index 053b993..712c618 100644 --- a/dhall/src/parser.rs +++ b/dhall/src/parser.rs @@ -240,12 +240,6 @@ macro_rules! binop { }; } -macro_rules! single { - ($pair:expr; $ty:ident) => { - match_children!($pair; (expr: $ty) => expr) - }; -} - macro_rules! with_rule { ($pair:expr; $x:ident; $submac:ident!( $($args:tt)* )) => { { @@ -347,16 +341,21 @@ make_parser!{ bx(Expr::Pi(label, typ, body)) }), + Rule::arrow_expression => + match_children!((typ: expression, body: expression) => { + bx(Expr::Pi("_", typ, body)) + }), + Rule::annotated_expression => binop!(Expr::Annot), - Rule::import_alt_expression => single!(expression), + Rule::import_alt_expression => binop!(Expr::ImportAlt), Rule::or_expression => binop!(Expr::BoolOr), Rule::plus_expression => binop!(Expr::NaturalPlus), Rule::text_append_expression => binop!(Expr::TextAppend), - Rule::list_append_expression => single!(expression), + Rule::list_append_expression => binop!(Expr::ListAppend), Rule::and_expression => binop!(Expr::BoolAnd), - Rule::combine_expression => single!(expression), - Rule::prefer_expression => single!(expression), - Rule::combine_types_expression => single!(expression), + Rule::combine_expression => binop!(Expr::Combine), + Rule::prefer_expression => binop!(Expr::Prefer), + Rule::combine_types_expression => binop!(Expr::CombineTypes), Rule::times_expression => binop!(Expr::NaturalTimes), Rule::equal_expression => binop!(Expr::BoolEQ), Rule::not_equal_expression => binop!(Expr::BoolNE), |