summaryrefslogtreecommitdiff
path: root/dhall/src/syntax
diff options
context:
space:
mode:
authorNadrieril2020-03-11 17:26:09 +0000
committerNadrieril2020-03-11 17:26:09 +0000
commit66972b05e5996132a83332ef0c6879c3a1679dc7 (patch)
treea6c148a6513063b14a1aebe53dd4a0cc927ecb3a /dhall/src/syntax
parent65e8aa46344b9dc32c3ad776856791d18cc616c3 (diff)
Implement record puns
Diffstat (limited to '')
-rw-r--r--dhall/src/syntax/ast/span.rs1
-rw-r--r--dhall/src/syntax/text/dhall.pest.visibility2
-rw-r--r--dhall/src/syntax/text/parser.rs5
-rw-r--r--dhall/src/syntax/text/printer.rs2
4 files changed, 9 insertions, 1 deletions
diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs
index 50985e1..153a624 100644
--- a/dhall/src/syntax/ast/span.rs
+++ b/dhall/src/syntax/ast/span.rs
@@ -22,6 +22,7 @@ pub(crate) enum Span {
DuplicateRecordFieldsSugar,
DottedFieldSugar,
WithSugar,
+ RecordPunSugar,
/// For expressions obtained from decoding binary
Decoded,
/// For expressions constructed during normalization/typecheck
diff --git a/dhall/src/syntax/text/dhall.pest.visibility b/dhall/src/syntax/text/dhall.pest.visibility
index 0ff1bfe..2a89076 100644
--- a/dhall/src/syntax/text/dhall.pest.visibility
+++ b/dhall/src/syntax/text/dhall.pest.visibility
@@ -184,6 +184,8 @@ non_empty_record_type
record_type_entry
non_empty_record_literal
record_literal_entry
+# record_literal_punned_entry
+# record_literal_normal_entry
union_type
empty_union_type
# non_empty_union_type
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index f59cf06..b3c2c40 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -954,6 +954,11 @@ impl DhallParser {
fn record_literal_entry(input: ParseInput) -> ParseResult<(Label, Expr)> {
Ok(match_nodes!(input.into_children();
+ [label(name)] => {
+ // Desugar record pun into a variable
+ let expr = Expr::new(Var(name.clone().into()), Span::RecordPunSugar);
+ (name, expr)
+ },
[label(name), expression(expr)] => (name, expr),
[label(first_name), label(names).., expression(expr)] => {
// Desugar dotted field syntax into nested records
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 5bb987b..a8991b0 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -357,7 +357,7 @@ impl Display for Label {
let s = String::from(self);
let is_reserved = match s.as_str() {
"let" | "in" | "if" | "then" | "else" | "Type" | "Kind"
- | "Sort" | "True" | "False" => true,
+ | "Sort" | "True" | "False" | "Some" => true,
_ => crate::syntax::Builtin::parse(&s).is_some(),
};
if !is_reserved && s.chars().all(|c| c.is_ascii_alphanumeric()) {