summaryrefslogtreecommitdiff
path: root/dhall_core/src/parser.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-23 23:24:11 +0100
committerNadrieril2019-03-23 23:24:11 +0100
commit062fc44a93a18ee432e51db852290ab5849f4dd9 (patch)
treec9dd53daf9cd99f5dcf982e1d98099a078f63110 /dhall_core/src/parser.rs
parentf610bc0aac5eaa365c95b489fb2d06cab449ec77 (diff)
Handle merge and record projection
Diffstat (limited to 'dhall_core/src/parser.rs')
-rw-r--r--dhall_core/src/parser.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs
index f959d2e..a62f861 100644
--- a/dhall_core/src/parser.rs
+++ b/dhall_core/src/parser.rs
@@ -19,6 +19,12 @@ pub type ParseError = pest::error::Error<Rule>;
pub type ParseResult<T> = Result<T, ParseError>;
+#[derive(Debug)]
+enum Either<A, B> {
+ Left(A),
+ Right(B),
+}
+
impl Builtin {
pub fn parse(s: &str) -> Option<Self> {
use self::Builtin::*;
@@ -649,13 +655,20 @@ make_parser! {
rule!(selector_expression<ParsedExpr> as expression; children!(
[expression(e)] => e,
[expression(first), selector(rest..)] => {
- rest.fold(first, |acc, e| bx(Expr::Field(acc, e)))
+ rest.fold(first, |acc, e| match e {
+ Either::Left(l) => bx(Expr::Field(acc, l)),
+ Either::Right(ls) => bx(Expr::Projection(acc, ls)),
+ })
}
));
- // TODO: handle record projection
- rule!(selector<Label>; children!(
- [label(l)] => l
+ rule!(selector<Either<Label, Vec<Label>>>; children!(
+ [label(l)] => Either::Left(l),
+ [labels(ls)] => Either::Right(ls),
+ ));
+
+ rule!(labels<Vec<Label>>; children!(
+ [label(ls..)] => ls.collect(),
));
rule!(literal_expression<ParsedExpr> as expression; children!(