diff options
author | Nadrieril Feneanar | 2019-11-11 18:30:36 +0100 |
---|---|---|
committer | GitHub | 2019-11-11 18:30:36 +0100 |
commit | bbb089d219cb22751d7100fe6524063cbe2474dd (patch) | |
tree | 4c64231fd014215b962cb294d4672d6785326372 /dhall_syntax/src/parser.rs | |
parent | 84cd6f386d6f4c7952fbc1da87dcd754f26ee404 (diff) | |
parent | facd2c587d96510c5a808f19d37b40c1fc2d2618 (diff) |
Merge pull request #115 from Nadrieril/parse-selection-be-expr
Parse projection by expression
Diffstat (limited to 'dhall_syntax/src/parser.rs')
-rw-r--r-- | dhall_syntax/src/parser.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index eaded50..f5d161f 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -24,9 +24,10 @@ pub type ParseError = pest::error::Error<Rule>; pub type ParseResult<T> = Result<T, ParseError>; #[derive(Debug)] -enum Either<A, B> { - Left(A), - Right(B), +enum Selector<E> { + Field(Label), + Projection(DupTreeSet<Label>), + ProjectionByExpr(Expr<E>), } impl crate::Builtin { @@ -777,8 +778,9 @@ impl DhallParser { acc.span(), e.1, match e.0 { - Either::Left(l) => Field(acc, l), - Either::Right(ls) => Projection(acc, ls), + Selector::Field(l) => Field(acc, l), + Selector::Projection(ls) => Projection(acc, ls), + Selector::ProjectionByExpr(e) => ProjectionByExpr(acc, e) } ) } @@ -787,14 +789,15 @@ impl DhallParser { )) } - fn selector( + fn selector<E: Clone>( input: ParseInput, - ) -> ParseResult<(Either<Label, DupTreeSet<Label>>, Span)> { - Ok(match_nodes!(input.children(); - [label(l)] => (Either::Left(l), input_to_span(input)), - [labels(ls)] => (Either::Right(ls), input_to_span(input)), - // [expression(_e)] => unimplemented!("selection by expression"), // TODO - )) + ) -> ParseResult<(Selector<E>, Span)> { + let stor = match_nodes!(input.children(); + [label(l)] => Selector::Field(l), + [labels(ls)] => Selector::Projection(ls), + [expression(e)] => Selector::ProjectionByExpr(e), + ); + Ok((stor, input_to_span(input))) } fn labels(input: ParseInput) -> ParseResult<DupTreeSet<Label>> { |