From 54d7e61ad40682ee24e36288980ee4164ea87c34 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 18:38:05 +0000 Subject: Update dhall-lang submodule --- dhall/src/syntax/text/printer.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 78942ed..dff3479 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -322,6 +322,8 @@ impl Display for NaiveDouble { f.write_str("-Infinity") } else if v.is_nan() { f.write_str("NaN") + } else if v == 0.0 && v.is_sign_negative() { + f.write_str("-0.0") } else { let s = format!("{}", v); if s.contains('e') || s.contains('.') { -- cgit v1.2.3 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 From 5536fe26187952a51087416ddd294d1da1ec689d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 19:14:29 +0000 Subject: rustfmt --- dhall/src/syntax/text/printer.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 759e7e6..626ab1c 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -64,7 +64,9 @@ 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)), + Completion(a, b) => { + Completion(a.phase(Primitive), b.phase(Primitive)) + } e => e, } } @@ -90,9 +92,10 @@ 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(_, _) | Completion(_, _) => { - phase > PrintPhase::Import - } + Field(_, _) + | Projection(_, _) + | ProjectionByExpr(_, _) + | Completion(_, _) => phase > PrintPhase::Import, _ => false, }; -- cgit v1.2.3 From 0e928ebde4ab8b662499eb716f366b97479c75fc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 23 Dec 2019 21:59:47 +0000 Subject: Add two new Integer builtins --- dhall/src/syntax/text/parser.rs | 2 ++ dhall/src/syntax/text/printer.rs | 2 ++ 2 files changed, 4 insertions(+) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index fe34aee..d9e5c3b 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -57,6 +57,8 @@ impl crate::syntax::Builtin { "Natural/subtract" => Some(NaturalSubtract), "Integer/toDouble" => Some(IntegerToDouble), "Integer/show" => Some(IntegerShow), + "Integer/negate" => Some(IntegerNegate), + "Integer/clamp" => Some(IntegerClamp), "Double/show" => Some(DoubleShow), "List/build" => Some(ListBuild), "List/fold" => Some(ListFold), diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 626ab1c..96f4c2a 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -468,6 +468,8 @@ impl Display for Builtin { NaturalShow => "Natural/show", NaturalSubtract => "Natural/subtract", IntegerToDouble => "Integer/toDouble", + IntegerNegate => "Integer/negate", + IntegerClamp => "Integer/clamp", IntegerShow => "Integer/show", DoubleShow => "Double/show", ListBuild => "List/build", -- cgit v1.2.3 From 4c7deccba50cb6d46134362128e3cb25c693c153 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 23 Dec 2019 22:30:27 +0000 Subject: Update dhall-lang submodule --- dhall/src/syntax/text/parser.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index d9e5c3b..27e0382 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -217,19 +217,18 @@ impl DhallParser { "t" => "\t".to_owned(), // "uXXXX" or "u{XXXXX}" s => { - use std::convert::{TryFrom, TryInto}; + use std::convert::TryInto; let s = &s[1..]; let s = if &s[0..1] == "{" { &s[1..s.len() - 1] } else { - &s[0..s.len()] + s }; if s.len() > 8 { Err(input.error(format!( - "Escape sequences can't have more than 8 chars: \"{}\"", - s + "Escape sequences can't have more than 8 chars" )))? } @@ -242,12 +241,10 @@ impl DhallParser { // `s` has length 8, so `bytes` has length 4 let bytes: &[u8] = &hex::decode(s).unwrap(); let i = u32::from_be_bytes(bytes.try_into().unwrap()); - let c = char::try_from(i).unwrap(); match i { - 0xD800..=0xDFFF => { - let c_ecapsed = c.escape_unicode(); - Err(input.error(format!("Escape sequences can't contain surrogate pairs: \"{}\"", c_ecapsed)))? - } + 0xD800..=0xDFFF => Err(input.error(format!( + "Escape sequences can't contain surrogate pairs" + )))?, 0x0FFFE..=0x0FFFF | 0x1FFFE..=0x1FFFF | 0x2FFFE..=0x2FFFF @@ -264,12 +261,12 @@ impl DhallParser { | 0xDFFFE..=0xDFFFF | 0xEFFFE..=0xEFFFF | 0xFFFFE..=0xFFFFF - | 0x10_FFFE..=0x10_FFFF => { - let c_ecapsed = c.escape_unicode(); - Err(input.error(format!("Escape sequences can't contain non-characters: \"{}\"", c_ecapsed)))? - } + | 0x10_FFFE..=0x10_FFFF => Err(input.error(format!( + "Escape sequences can't contain non-characters" + )))?, _ => {} } + let c: char = i.try_into().unwrap(); std::iter::once(c).collect() } }) -- cgit v1.2.3 From 12d6a22c7dcdc0cb6e169b082b4553caec0e6027 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 23 Dec 2019 22:48:51 +0000 Subject: Update dhall-lang submodule --- dhall/src/syntax/text/parser.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 27e0382..0e3e97a 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -383,19 +383,27 @@ impl DhallParser { } fn natural_literal(input: ParseInput) -> ParseResult { - input - .as_str() - .trim() - .parse() - .map_err(|e| input.error(format!("{}", e))) + let s = input.as_str().trim(); + if s.starts_with("0x") { + let without_prefix = s.trim_start_matches("0x"); + usize::from_str_radix(without_prefix, 16) + .map_err(|e| input.error(format!("{}", e))) + } else { + s.parse().map_err(|e| input.error(format!("{}", e))) + } } fn integer_literal(input: ParseInput) -> ParseResult { - input - .as_str() - .trim() - .parse() - .map_err(|e| input.error(format!("{}", e))) + let s = input.as_str().trim(); + let (sign, rest) = (&s[0..1], &s[1..]); + if rest.starts_with("0x") { + let without_prefix = + sign.to_owned() + rest.trim_start_matches("0x"); + isize::from_str_radix(&without_prefix, 16) + .map_err(|e| input.error(format!("{}", e))) + } else { + s.parse().map_err(|e| input.error(format!("{}", e))) + } } #[alias(expression, shortcut = true)] -- cgit v1.2.3 From 5f52c5bda0277edd87323eb67dcda721cd18a9d3 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 24 Dec 2019 20:23:19 +0000 Subject: Extend merge to work on Optionals --- dhall/src/syntax/text/parser.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 0e3e97a..feaa2a5 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -183,6 +183,15 @@ impl DhallParser { Ok(Label::from(input.as_str())) } + // TODO: waiting for https://github.com/dhall-lang/dhall-lang/pull/871 + // #[alias(label)] + // fn any_label_or_some(input: ParseInput) -> ParseResult