diff options
author | Nadrieril Feneanar | 2020-02-20 20:22:39 +0000 |
---|---|---|
committer | GitHub | 2020-02-20 20:22:39 +0000 |
commit | 92b5604c1049a771239a70ab14c393e8e1807c68 (patch) | |
tree | 73ffbfd6417da6b8c650ba17c40c376dc7b23c4a /dhall/src/syntax/ast | |
parent | ffbde252a850c7d96e1000e1be52792c41733a28 (diff) | |
parent | e5f0602e431bc602f9e1f0045f48056ce6465481 (diff) |
Merge pull request #132 from Nadrieril/catchup-spec
Catchup spec
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r-- | dhall/src/syntax/ast/expr.rs | 23 | ||||
-rw-r--r-- | dhall/src/syntax/ast/mod.rs | 2 | ||||
-rw-r--r-- | dhall/src/syntax/ast/span.rs | 34 |
3 files changed, 13 insertions, 46 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index a479b53..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<SubExpr> { /// `{ k1 : t1, k2 : t1 }` RecordType(DupTreeMap<Label, SubExpr>), /// `{ k1 = v1, k2 = v2 }` - RecordLit(DupTreeMap<Label, SubExpr>), + RecordLit(BTreeMap<Label, SubExpr>), /// `< k1 : t1, k2 >` UnionType(DupTreeMap<Label, Option<SubExpr>>), /// `merge x y : t` @@ -237,32 +239,19 @@ impl<SE> ExprKind<SE> { } 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 { - Expr { - kind: Box::new(kind), - span, - } - } - - pub fn rewrap(&self, kind: UnspannedExpr) -> Expr { + pub(crate) fn new(kind: UnspannedExpr, span: Span) -> Self { Expr { kind: Box::new(kind), - span: self.span.clone(), - } - } - pub fn with_span(self, span: Span) -> Self { - Expr { - kind: self.kind, span, } } 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..7c004c5 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<str>, /// # Safety /// @@ -15,9 +15,12 @@ pub struct ParsedSpan { } #[derive(Debug, Clone)] -pub enum Span { +pub(crate) enum Span { /// A location in the source text Parsed(ParsedSpan), + /// Desugarings + DuplicateRecordFieldsSugar, + DottedFieldSugar, /// For expressions obtained from decoding binary Decoded, /// For expressions constructed during normalization/typecheck @@ -50,7 +53,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 +70,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>) -> 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. |