From cc03ada4e713f145f2eb1bbf0f131a4c5746cf74 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 3 Aug 2019 22:55:51 +0200 Subject: Inline headers --- dhall_syntax/src/core/import.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs index c328e34..306460b 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall_syntax/src/core/import.rs @@ -26,6 +26,7 @@ pub struct URL { pub authority: String, pub path: Vec, pub query: Option, + // TODO: implement inline headers pub headers: Option>, } -- cgit v1.2.3 From 711164a7a24ab832006b72cac162e78cf434861a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 11:11:37 +0200 Subject: Remove old-style optional literals --- dhall_syntax/src/core/expr.rs | 4 ---- dhall_syntax/src/core/visitor.rs | 4 ---- dhall_syntax/src/parser.rs | 18 +++--------------- dhall_syntax/src/printer.rs | 8 -------- 4 files changed, 3 insertions(+), 31 deletions(-) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index da9465d..df2dc97 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -194,10 +194,6 @@ pub enum ExprF { EmptyListLit(SubExpr), /// `[x, y, z]` NEListLit(Vec), - /// Deprecated Optional literal form - /// `[] : Optional a` - /// `[x] : Optional a` - OldOptionalLit(Option, SubExpr), /// `Some e` SomeLit(SubExpr), /// `{ k1 : t1, k2 : t1 }` diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs index 99a9c11..1745fdb 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall_syntax/src/core/visitor.rs @@ -137,10 +137,6 @@ where ), EmptyListLit(t) => EmptyListLit(v.visit_subexpr(t)?), NEListLit(es) => NEListLit(vec(es, |e| v.visit_subexpr(e))?), - OldOptionalLit(x, t) => OldOptionalLit( - opt(x, |e| v.visit_subexpr(e))?, - v.visit_subexpr(t)?, - ), SomeLit(e) => SomeLit(v.visit_subexpr(e)?), RecordType(kts) => RecordType(dupmap(kts, v)?), RecordLit(kvs) => RecordLit(dupmap(kvs, v)?), diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 9d9a374..db1699b 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -724,6 +724,9 @@ make_parser! { [merge(()), expression(x), expression(y), expression(z)] => { spanned(span, Merge(x, y, Some(z))) }, + [List(()), expression(x)] => { + spanned(span, EmptyListLit(x)) + }, [expression(e)] => e, )); @@ -738,21 +741,6 @@ make_parser! { token_rule!(List<()>); token_rule!(Optional<()>); - rule!(empty_collection as expression; span; children!( - [List(_), expression(t)] => { - spanned(span, EmptyListLit(t)) - }, - [Optional(_), expression(t)] => { - spanned(span, OldOptionalLit(None, t)) - }, - )); - - rule!(non_empty_optional as expression; span; children!( - [expression(x), Optional(_), expression(t)] => { - spanned(span, OldOptionalLit(Some(x), t)) - } - )); - rule!(import_alt_expression as expression; children!( [expression(e)] => e, [expression(first), expression(rest)..] => { diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index dbed55d..b585a5b 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -32,12 +32,6 @@ impl Display for ExprF { NEListLit(es) => { fmt_list("[", ", ", "]", es, f, Display::fmt)?; } - OldOptionalLit(None, t) => { - write!(f, "[] : Optional {}", t)?; - } - OldOptionalLit(Some(x), t) => { - write!(f, "[{}] : Optional {}", x, t)?; - } SomeLit(e) => { write!(f, "Some {}", e)?; } @@ -154,7 +148,6 @@ impl Expr { | Let(_, _, _, _) | EmptyListLit(_) | NEListLit(_) - | OldOptionalLit(_, _) | SomeLit(_) | Merge(_, _, _) | Annot(_, _) @@ -190,7 +183,6 @@ impl Expr { b.phase(PrintPhase::BinOp(op)), ), EmptyListLit(t) => EmptyListLit(t.phase(Import)), - OldOptionalLit(x, t) => OldOptionalLit(x, t.phase(Import)), SomeLit(e) => SomeLit(e.phase(Import)), ExprF::App(f, a) => ExprF::App(f.phase(Import), a.phase(Import)), Field(a, b) => Field(a.phase(Primitive), b), -- cgit v1.2.3 From 696efe66336a268054c475fab9fe6505bdfc7b60 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 13:00:56 +0200 Subject: Add some new tests and implement import alternatives --- dhall_syntax/src/core/expr.rs | 39 +++++++++++++++++++++++++++++++++++++++ dhall_syntax/src/core/visitor.rs | 25 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index df2dc97..e33859b 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -307,6 +307,35 @@ impl Expr { { trivial_result(self.traverse_embed(|x| Ok(map_embed(x)))) } + + pub fn traverse_resolve( + &self, + visit_embed: impl FnMut(&E) -> Result, + ) -> Result, Err> + where + N: Clone, + { + self.traverse_resolve_with_visitor(&mut visitor::ResolveVisitor( + visit_embed, + )) + } + + pub(crate) fn traverse_resolve_with_visitor( + &self, + visitor: &mut visitor::ResolveVisitor, + ) -> Result, Err> + where + N: Clone, + F1: FnMut(&E) -> Result, + { + match self { + ExprF::BinOp(BinOp::ImportAlt, l, r) => l + .as_ref() + .traverse_resolve_with_visitor(visitor) + .or(r.as_ref().traverse_resolve_with_visitor(visitor)), + _ => self.visit(visitor), + } + } } impl Expr { @@ -383,6 +412,16 @@ impl SubExpr { )), } } + + pub fn traverse_resolve( + &self, + visit_embed: impl FnMut(&E) -> Result, + ) -> Result, Err> + where + N: Clone, + { + Ok(self.rewrap(self.as_ref().traverse_resolve(visit_embed)?)) + } } impl SubExpr { diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs index 1745fdb..b02544f 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall_syntax/src/core/visitor.rs @@ -358,6 +358,31 @@ where } } +pub struct ResolveVisitor(pub F1); + +impl<'a, 'b, N, E, E2, Err, F1> + ExprFFallibleVisitor<'a, SubExpr, SubExpr, E, E2> + for &'b mut ResolveVisitor +where + N: Clone + 'a, + F1: FnMut(&E) -> Result, +{ + type Error = Err; + + fn visit_subexpr( + &mut self, + subexpr: &'a SubExpr, + ) -> Result, Self::Error> { + Ok(subexpr.rewrap( + subexpr + .as_ref() + .traverse_resolve_with_visitor(&mut **self)?, + )) + } + fn visit_embed(self, embed: &'a E) -> Result { + (self.0)(embed) + } +} pub struct NoteAbsurdVisitor; impl<'a, 'b, N, E> -- cgit v1.2.3 From e52f50080d8e0e6d6a05b1045e3e0e840acb50d0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 14:07:34 +0200 Subject: Braced escape sequences --- dhall_syntax/src/parser.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index db1699b..2450c76 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -402,11 +402,31 @@ make_parser! { "n" => "\n".to_owned(), "r" => "\r".to_owned(), "t" => "\t".to_owned(), + // "uXXXX" or "u{XXXXX}" _ => { - // "uXXXX" - use std::convert::TryFrom; - let c = u16::from_str_radix(&s[1..5], 16).unwrap(); - let c = char::try_from(u32::from(c)).unwrap(); + use std::convert::{TryFrom, TryInto}; + + let s = &s[1..]; + let s = if &s[0..1] == "{" { + &s[1..s.len()-1] + } else { + &s[0..s.len()] + }; + + if s.len() > 8 { + Err(format!("Escape sequences can't have more than 8 chars: \"{}\"", s))? + } + + // pad with zeroes + let s: String = std::iter::repeat('0') + .take(8 - s.len()) + .chain(s.chars()) + .collect(); + + // `s` has length 8, so `bytes` has length 4 + let bytes: &[u8] = &hex::decode(s).unwrap(); + let c = u32::from_be_bytes(bytes.try_into().unwrap()); + let c = char::try_from(c).unwrap(); std::iter::once(c).collect() } } -- cgit v1.2.3 From 482be29e0f03e10c2469ef80bdd6ac7593207dc5 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 20:38:06 +0200 Subject: RFC3986 URLs --- dhall_syntax/src/core/import.rs | 1 + dhall_syntax/src/parser.rs | 7 +++++++ dhall_syntax/src/printer.rs | 1 + 3 files changed, 9 insertions(+) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs index 306460b..d41eae2 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall_syntax/src/core/import.rs @@ -41,6 +41,7 @@ pub enum Scheme { pub enum ImportMode { Code, RawText, + Location, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 2450c76..2c0cee9 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -697,6 +697,7 @@ make_parser! { )); token_rule!(Text<()>); + token_rule!(Location<()>); rule!(import as expression; span; children!( [import_hashed(location_hashed)] => { @@ -711,6 +712,12 @@ make_parser! { location_hashed })) }, + [import_hashed(location_hashed), Location(_)] => { + spanned(span, Embed(Import { + mode: ImportMode::Location, + location_hashed + })) + }, )); token_rule!(lambda<()>); diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index b585a5b..2b2bbcc 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -435,6 +435,7 @@ impl Display for Import { match self.mode { Code => {} RawText => write!(f, " as Text")?, + Location => write!(f, " as Location")?, } Ok(()) } -- cgit v1.2.3 From 3e157f0a05b0b93753ed377332597a37fa379541 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 21:28:12 +0200 Subject: Add toMap keyword --- dhall_syntax/src/parser.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 2c0cee9..8355ebf 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -861,6 +861,7 @@ make_parser! { )); token_rule!(Some_<()>); + token_rule!(toMap<()>); rule!(application_expression as expression; children!( [expression(e)] => e, -- cgit v1.2.3 From 705433487da3cd3b4517fcf74b0497c76dbb4080 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 22:36:43 +0200 Subject: Prepare for https://github.com/dhall-lang/dhall-lang/pull/630 --- dhall_syntax/src/parser.rs | 3 ++- dhall_syntax/src/printer.rs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 8355ebf..0832af3 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -752,7 +752,8 @@ make_parser! { spanned(span, Merge(x, y, Some(z))) }, [List(()), expression(x)] => { - spanned(span, EmptyListLit(x)) + let list = unspanned(Builtin(crate::Builtin::List)); + spanned(span, EmptyListLit(unspanned(App(list, x)))) }, [expression(e)] => e, )); diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index 2b2bbcc..52d3d81 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -27,7 +27,7 @@ impl Display for ExprF { write!(f, " = {} in {}", c, d)?; } EmptyListLit(t) => { - write!(f, "[] : List {}", t)?; + write!(f, "[] : {}", t)?; } NEListLit(es) => { fmt_list("[", ", ", "]", es, f, Display::fmt)?; @@ -182,7 +182,6 @@ impl Expr { a.phase(PrintPhase::BinOp(op)), b.phase(PrintPhase::BinOp(op)), ), - EmptyListLit(t) => EmptyListLit(t.phase(Import)), SomeLit(e) => SomeLit(e.phase(Import)), ExprF::App(f, a) => ExprF::App(f.phase(Import), a.phase(Import)), Field(a, b) => Field(a.phase(Primitive), b), -- cgit v1.2.3 From f7b0c6b9c52f65624dc765fb9eaa7d0d94eeae76 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 23:03:01 +0200 Subject: Generalize empty list annotations --- dhall_syntax/src/core/expr.rs | 2 +- dhall_syntax/src/parser.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index e33859b..14dc165 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -190,7 +190,7 @@ pub enum ExprF { DoubleLit(Double), /// `"Some ${interpolated} text"` TextLit(InterpolatedText), - /// `[] : List t` + /// `[] : t` EmptyListLit(SubExpr), /// `[x, y, z]` NEListLit(Vec), diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 0832af3..8a84b00 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -727,6 +727,12 @@ make_parser! { token_rule!(if_<()>); token_rule!(in_<()>); + rule!(empty_list_literal as expression; span; children!( + [expression(e)] => { + spanned(span, EmptyListLit(e)) + }, + )); + rule!(expression as expression; span; children!( [lambda(()), label(l), expression(typ), arrow(()), expression(body)] => { @@ -751,10 +757,6 @@ make_parser! { [merge(()), expression(x), expression(y), expression(z)] => { spanned(span, Merge(x, y, Some(z))) }, - [List(()), expression(x)] => { - let list = unspanned(Builtin(crate::Builtin::List)); - spanned(span, EmptyListLit(unspanned(App(list, x)))) - }, [expression(e)] => e, )); -- cgit v1.2.3 From 2755cb01092363062016bc51349870b1330d1d6f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 15:58:57 +0200 Subject: Sort labels in projection expressions --- dhall_syntax/src/core/expr.rs | 4 +- dhall_syntax/src/core/map.rs | 95 +++++++++++++++++++++++++++++++++++++++++++ dhall_syntax/src/parser.rs | 6 +-- 3 files changed, 100 insertions(+), 5 deletions(-) (limited to 'dhall_syntax/src') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 14dc165..668ab45 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use crate::map::DupTreeMap; +use crate::map::{DupTreeMap, DupTreeSet}; use crate::visitor; use crate::*; @@ -209,7 +209,7 @@ pub enum ExprF { /// `e.x` Field(SubExpr, Label), /// `e.{ x, y, z }` - Projection(SubExpr, Vec