From e294450e1e76491e96019b8a3695463e09d1739b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 19:02:18 +0000 Subject: Implement parsing for record completion --- dhall/src/syntax/text/parser.rs | 19 +++++++++++++++++++ dhall/src/syntax/text/printer.rs | 20 ++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 832472b..fe34aee 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -765,6 +765,25 @@ impl DhallParser { )) } + #[alias(expression, shortcut = true)] + fn completion_expression(input: ParseInput) -> ParseResult { + Ok(match_nodes!(input.children(); + [expression(e)] => e, + [expression(first), expression(rest)..] => { + rest.fold( + first, + |acc, e| { + spanned_union( + acc.span(), + e.span(), + Completion(acc, e), + ) + } + ) + }, + )) + } + #[alias(expression, shortcut = true)] fn selector_expression(input: ParseInput) -> ParseResult { Ok(match_nodes!(input.children(); diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index dff3479..759e7e6 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -64,6 +64,7 @@ impl UnspannedExpr { Field(a, b) => Field(a.phase(Primitive), b), Projection(e, ls) => Projection(e.phase(Primitive), ls), ProjectionByExpr(a, b) => ProjectionByExpr(a.phase(Primitive), b), + Completion(a, b) => Completion(a.phase(Primitive), b.phase(Primitive)), e => e, } } @@ -89,7 +90,7 @@ impl UnspannedExpr { // Precedence is magically handled by the ordering of BinOps. ExprKind::BinOp(op, _, _) => phase > PrintPhase::BinOp(*op), ExprKind::App(_, _) => phase > PrintPhase::App, - Field(_, _) | Projection(_, _) | ProjectionByExpr(_, _) => { + Field(_, _) | Projection(_, _) | ProjectionByExpr(_, _) | Completion(_, _) => { phase > PrintPhase::Import } _ => false, @@ -189,13 +190,6 @@ impl Display for ExprKind { Field(a, b) => { write!(f, "{}.{}", a, b)?; } - Projection(e, ls) => { - write!(f, "{}.", e)?; - fmt_list("{ ", ", ", " }", ls, f, Display::fmt)?; - } - ProjectionByExpr(a, b) => { - write!(f, "{}.({})", a, b)?; - } Var(a) => a.fmt(f)?, Const(k) => k.fmt(f)?, Builtin(v) => v.fmt(f)?, @@ -224,6 +218,16 @@ impl Display for ExprKind { } Ok(()) })?, + Projection(e, ls) => { + write!(f, "{}.", e)?; + fmt_list("{ ", ", ", " }", ls, f, Display::fmt)?; + } + ProjectionByExpr(a, b) => { + write!(f, "{}.({})", a, b)?; + } + Completion(a, b) => { + write!(f, "{}::{}", a, b)?; + } Import(a) => a.fmt(f)?, Embed(a) => a.fmt(f)?, } -- cgit v1.2.3