From 26ed5a1d4d43573ac8ad2f8de9e4dd411650aa9a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 19 Feb 2020 17:24:41 +0000 Subject: Expose fewer pub things --- dhall/src/syntax/ast/expr.rs | 19 +++---------------- dhall/src/syntax/ast/mod.rs | 2 +- dhall/src/syntax/ast/span.rs | 31 +++---------------------------- 3 files changed, 7 insertions(+), 45 deletions(-) (limited to 'dhall/src/syntax/ast') diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index a479b53..089c178 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -237,35 +237,22 @@ impl ExprKind { } impl Expr { - pub fn as_ref(&self) -> &UnspannedExpr { + pub(crate) fn as_ref(&self) -> &UnspannedExpr { &self.kind } pub fn kind(&self) -> &UnspannedExpr { &self.kind } - pub fn span(&self) -> Span { + pub(crate) fn span(&self) -> Span { self.span.clone() } - pub fn new(kind: UnspannedExpr, span: Span) -> Self { + pub(crate) fn new(kind: UnspannedExpr, span: Span) -> Self { Expr { kind: Box::new(kind), span, } } - - pub fn rewrap(&self, kind: UnspannedExpr) -> Expr { - Expr { - kind: Box::new(kind), - span: self.span.clone(), - } - } - pub fn with_span(self, span: Span) -> Self { - Expr { - kind: self.kind, - span, - } - } } pub fn trivial_result(x: Result) -> T { diff --git a/dhall/src/syntax/ast/mod.rs b/dhall/src/syntax/ast/mod.rs index 1950154..5e20c5d 100644 --- a/dhall/src/syntax/ast/mod.rs +++ b/dhall/src/syntax/ast/mod.rs @@ -5,7 +5,7 @@ pub use import::*; mod label; pub use label::*; mod span; -pub use span::*; +pub(crate) use span::*; mod text; pub use text::*; pub mod map; diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs index fba6a2d..e75ea53 100644 --- a/dhall/src/syntax/ast/span.rs +++ b/dhall/src/syntax/ast/span.rs @@ -2,7 +2,7 @@ use std::rc::Rc; /// A location in the source text #[derive(Debug, Clone)] -pub struct ParsedSpan { +pub(crate) struct ParsedSpan { input: Rc, /// # Safety /// @@ -15,7 +15,7 @@ pub struct ParsedSpan { } #[derive(Debug, Clone)] -pub enum Span { +pub(crate) enum Span { /// A location in the source text Parsed(ParsedSpan), /// For expressions obtained from decoding binary @@ -50,7 +50,7 @@ impl Span { /// Takes the union of the two spans, i.e. the range of input covered by the two spans plus any /// input between them. Assumes that the spans come from the same input. Fails if one of the /// spans does not point to an input location. - pub fn union(&self, other: &Span) -> Self { + pub(crate) fn union(&self, other: &Span) -> Self { use std::cmp::{max, min}; use Span::*; match (self, other) { @@ -67,31 +67,6 @@ impl Span { ), } } - - /// Merges two spans assumed to point to a similar thing. If only one of them points to an - /// input location, use that one. - pub fn merge(&self, other: &Span) -> Self { - use Span::*; - match (self, other) { - (Parsed(x), _) | (_, Parsed(x)) => Parsed(x.clone()), - (Artificial, _) | (_, Artificial) => Artificial, - (Decoded, Decoded) => Decoded, - } - } - - pub fn error(&self, message: impl Into) -> String { - use pest::error::{Error, ErrorVariant}; - use pest::Span; - let message: String = message.into(); - let span = match self { - self::Span::Parsed(span) => span, - _ => return format!("[unknown location] {}", message), - }; - let span = Span::new(&*span.input, span.start, span.end).unwrap(); - let err: ErrorVariant = ErrorVariant::CustomError { message }; - let err = Error::new_from_span(err, span); - format!("{}", err) - } } /// Convert a byte idx into a string into a char idx for consumption by annotate_snippets. -- cgit v1.2.3 From 86508a3ad59a0bfc1e24448d0a0126b1a1c645e1 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 20 Feb 2020 18:52:34 +0000 Subject: Add support for duplicate record fields --- dhall/src/syntax/ast/expr.rs | 4 +++- dhall/src/syntax/ast/span.rs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'dhall/src/syntax/ast') diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index 089c178..ce0a3d2 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + use crate::semantics::Universe; use crate::syntax::map::{DupTreeMap, DupTreeSet}; use crate::syntax::visitor; @@ -165,7 +167,7 @@ pub enum ExprKind { /// `{ k1 : t1, k2 : t1 }` RecordType(DupTreeMap), /// `{ k1 = v1, k2 = v2 }` - RecordLit(DupTreeMap), + RecordLit(BTreeMap), /// `< k1 : t1, k2 >` UnionType(DupTreeMap>), /// `merge x y : t` diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs index e75ea53..6d017f6 100644 --- a/dhall/src/syntax/ast/span.rs +++ b/dhall/src/syntax/ast/span.rs @@ -18,6 +18,8 @@ pub(crate) struct ParsedSpan { pub(crate) enum Span { /// A location in the source text Parsed(ParsedSpan), + /// Desugaring of duplicate fields + DuplicateRecordFieldsSugar, /// For expressions obtained from decoding binary Decoded, /// For expressions constructed during normalization/typecheck -- cgit v1.2.3 From 6642077368497583113d685d351ec93d230ffcad Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 20 Feb 2020 19:04:13 +0000 Subject: Add support for dotted field syntax --- dhall/src/syntax/ast/span.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dhall/src/syntax/ast') diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs index 6d017f6..7c004c5 100644 --- a/dhall/src/syntax/ast/span.rs +++ b/dhall/src/syntax/ast/span.rs @@ -18,8 +18,9 @@ pub(crate) struct ParsedSpan { pub(crate) enum Span { /// A location in the source text Parsed(ParsedSpan), - /// Desugaring of duplicate fields + /// Desugarings DuplicateRecordFieldsSugar, + DottedFieldSugar, /// For expressions obtained from decoding binary Decoded, /// For expressions constructed during normalization/typecheck -- cgit v1.2.3