summaryrefslogtreecommitdiff
path: root/dhall/src/syntax
diff options
context:
space:
mode:
authorNadrieril Feneanar2020-03-05 16:20:07 +0000
committerGitHub2020-03-05 16:20:07 +0000
commit3f9194f47185fe30c9e410aa7c5e651df9694b3f (patch)
tree6d24b2e824822134da4976b65b413dc09ca4e567 /dhall/src/syntax
parent2ca97e97f1718141d826a78ab3da8197b2d55c69 (diff)
parent8e6b020ba1426c215382a81395b809b688fa7726 (diff)
Merge pull request #139 from Nadrieril/missing-features
Implement a bunch of missing features
Diffstat (limited to '')
-rw-r--r--dhall/src/syntax/ast/expr.rs2
-rw-r--r--dhall/src/syntax/ast/import.rs10
-rw-r--r--dhall/src/syntax/ast/text.rs29
-rw-r--r--dhall/src/syntax/binary/decode.rs10
-rw-r--r--dhall/src/syntax/binary/encode.rs28
-rw-r--r--dhall/src/syntax/text/parser.rs18
-rw-r--r--dhall/src/syntax/text/printer.rs4
7 files changed, 36 insertions, 65 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index bb1a5b3..ce0a3d2 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -178,7 +178,7 @@ pub enum ExprKind<SubExpr> {
Field(SubExpr, Label),
/// `e.{ x, y, z }`
Projection(SubExpr, DupTreeSet<Label>),
- /// `e.(s)`
+ /// `e.(t)`
ProjectionByExpr(SubExpr, SubExpr),
/// `x::y`
Completion(SubExpr, SubExpr),
diff --git a/dhall/src/syntax/ast/import.rs b/dhall/src/syntax/ast/import.rs
index 7bde6e0..75d7946 100644
--- a/dhall/src/syntax/ast/import.rs
+++ b/dhall/src/syntax/ast/import.rs
@@ -18,7 +18,7 @@ pub struct FilePath {
/// The location of import (i.e. local vs. remote vs. environment)
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub enum ImportLocation<SubExpr> {
+pub enum ImportTarget<SubExpr> {
Local(FilePrefix, FilePath),
Remote(URL<SubExpr>),
Env(String),
@@ -57,7 +57,7 @@ pub enum Hash {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Import<SubExpr> {
pub mode: ImportMode,
- pub location: ImportLocation<SubExpr>,
+ pub location: ImportTarget<SubExpr>,
pub hash: Option<Hash>,
}
@@ -77,12 +77,12 @@ impl<SE> URL<SE> {
}
}
-impl<SE> ImportLocation<SE> {
+impl<SE> ImportTarget<SE> {
pub fn traverse_ref<'a, Err, SE2>(
&'a self,
f: impl FnOnce(&'a SE) -> Result<SE2, Err>,
- ) -> Result<ImportLocation<SE2>, Err> {
- use ImportLocation::*;
+ ) -> Result<ImportTarget<SE2>, Err> {
+ use ImportTarget::*;
Ok(match self {
Local(prefix, path) => Local(*prefix, path.clone()),
Remote(url) => Remote(url.traverse_ref(f)?),
diff --git a/dhall/src/syntax/ast/text.rs b/dhall/src/syntax/ast/text.rs
index 83aaf9a..c40f4a1 100644
--- a/dhall/src/syntax/ast/text.rs
+++ b/dhall/src/syntax/ast/text.rs
@@ -54,16 +54,6 @@ impl<SubExpr> InterpolatedTextContents<SubExpr> {
Text(s) => Text(s.clone()),
})
}
- pub fn traverse_mut<'a, E, F>(&'a mut self, mut f: F) -> Result<(), E>
- where
- F: FnMut(&'a mut SubExpr) -> Result<(), E>,
- {
- use InterpolatedTextContents::Expr;
- if let Expr(e) = self {
- f(e)?;
- }
- Ok(())
- }
pub fn map_ref<'a, SubExpr2, F>(
&'a self,
mut f: F,
@@ -77,15 +67,6 @@ impl<SubExpr> InterpolatedTextContents<SubExpr> {
Text(s) => Text(s.clone()),
}
}
- pub fn map_mut<'a, F>(&'a mut self, mut f: F)
- where
- F: FnMut(&'a mut SubExpr),
- {
- use InterpolatedTextContents::Expr;
- if let Expr(e) = self {
- f(e);
- }
- }
}
impl<SubExpr> InterpolatedText<SubExpr> {
@@ -126,16 +107,6 @@ impl<SubExpr> InterpolatedText<SubExpr> {
})
}
- pub fn traverse_mut<'a, E, F>(&'a mut self, mut f: F) -> Result<(), E>
- where
- F: FnMut(&'a mut SubExpr) -> Result<(), E>,
- {
- for (e, _) in &mut self.tail {
- f(e)?
- }
- Ok(())
- }
-
pub fn iter<'a>(
&'a self,
) -> impl Iterator<Item = InterpolatedTextContents<&'a SubExpr>> + 'a {
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index 2e50d61..bebc800 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -5,7 +5,7 @@ use std::iter::FromIterator;
use crate::error::DecodeError;
use crate::syntax;
use crate::syntax::{
- Expr, ExprKind, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
+ Expr, ExprKind, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
Integer, InterpolatedText, Label, LitKind, Natural, Scheme, Span,
UnspannedExpr, URL, V,
};
@@ -305,7 +305,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
})
.collect::<Result<_, _>>()?;
let path = FilePath { file_path };
- ImportLocation::Remote(URL {
+ ImportTarget::Remote(URL {
scheme,
authority,
path,
@@ -332,7 +332,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
})
.collect::<Result<_, _>>()?;
let path = FilePath { file_path };
- ImportLocation::Local(prefix, path)
+ ImportTarget::Local(prefix, path)
}
6 => {
let env = match rest.next() {
@@ -341,9 +341,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
"import/env".to_owned(),
))?,
};
- ImportLocation::Env(env)
+ ImportTarget::Env(env)
}
- 7 => ImportLocation::Missing,
+ 7 => ImportTarget::Missing,
_ => Err(DecodeError::WrongFormatError(
"import/type".to_owned(),
))?,
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index d2aa240..2484d8d 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -6,8 +6,8 @@ use crate::error::EncodeError;
use crate::syntax;
use crate::syntax::map::DupTreeMap;
use crate::syntax::{
- Expr, ExprKind, FilePrefix, Hash, Import, ImportLocation, ImportMode,
- Label, Scheme, V,
+ Expr, ExprKind, FilePrefix, Hash, Import, ImportMode, ImportTarget, Label,
+ Scheme, V,
};
pub(crate) fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
@@ -179,10 +179,10 @@ where
use serde::ser::SerializeSeq;
let count = 4 + match &import.location {
- ImportLocation::Remote(url) => 3 + url.path.file_path.len(),
- ImportLocation::Local(_, path) => path.file_path.len(),
- ImportLocation::Env(_) => 1,
- ImportLocation::Missing => 0,
+ ImportTarget::Remote(url) => 3 + url.path.file_path.len(),
+ ImportTarget::Local(_, path) => path.file_path.len(),
+ ImportTarget::Env(_) => 1,
+ ImportTarget::Missing => 0,
};
let mut ser_seq = ser.serialize_seq(Some(count))?;
@@ -206,23 +206,23 @@ where
ser_seq.serialize_element(&U64(mode))?;
let scheme = match &import.location {
- ImportLocation::Remote(url) => match url.scheme {
+ ImportTarget::Remote(url) => match url.scheme {
Scheme::HTTP => 0,
Scheme::HTTPS => 1,
},
- ImportLocation::Local(prefix, _) => match prefix {
+ ImportTarget::Local(prefix, _) => match prefix {
FilePrefix::Absolute => 2,
FilePrefix::Here => 3,
FilePrefix::Parent => 4,
FilePrefix::Home => 5,
},
- ImportLocation::Env(_) => 6,
- ImportLocation::Missing => 7,
+ ImportTarget::Env(_) => 6,
+ ImportTarget::Missing => 7,
};
ser_seq.serialize_element(&U64(scheme))?;
match &import.location {
- ImportLocation::Remote(url) => {
+ ImportTarget::Remote(url) => {
match &url.headers {
None => ser_seq.serialize_element(&Null)?,
Some(e) => {
@@ -238,15 +238,15 @@ where
Some(x) => ser_seq.serialize_element(x)?,
};
}
- ImportLocation::Local(_, path) => {
+ ImportTarget::Local(_, path) => {
for p in path.file_path.iter() {
ser_seq.serialize_element(&p)?;
}
}
- ImportLocation::Env(env) => {
+ ImportTarget::Env(env) => {
ser_seq.serialize_element(env)?;
}
- ImportLocation::Missing => {}
+ ImportTarget::Missing => {}
}
ser_seq.end()
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index ba64a75..7140332 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -10,7 +10,7 @@ use crate::syntax::map::{DupTreeMap, DupTreeSet};
use crate::syntax::ExprKind::*;
use crate::syntax::LitKind::*;
use crate::syntax::{
- Double, Expr, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
+ Double, Expr, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
Integer, InterpolatedText, InterpolatedTextContents, Label, NaiveDouble,
Natural, Scheme, Span, UnspannedExpr, URL, V,
};
@@ -483,9 +483,9 @@ impl DhallParser {
}
#[alias(import_type)]
- fn local(input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
+ fn local(input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
Ok(match_nodes!(input.into_children();
- [local_path((prefix, p))] => ImportLocation::Local(prefix, p),
+ [local_path((prefix, p))] => ImportTarget::Local(prefix, p),
))
}
@@ -550,17 +550,17 @@ impl DhallParser {
}
#[alias(import_type)]
- fn http(input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
- Ok(ImportLocation::Remote(match_nodes!(input.into_children();
+ fn http(input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
+ Ok(ImportTarget::Remote(match_nodes!(input.into_children();
[http_raw(url)] => url,
[http_raw(url), expression(e)] => URL { headers: Some(e), ..url },
)))
}
#[alias(import_type)]
- fn env(input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
+ fn env(input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
Ok(match_nodes!(input.into_children();
- [environment_variable(v)] => ImportLocation::Env(v),
+ [environment_variable(v)] => ImportTarget::Env(v),
))
}
#[alias(environment_variable)]
@@ -593,8 +593,8 @@ impl DhallParser {
}
#[alias(import_type)]
- fn missing(_input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
- Ok(ImportLocation::Missing)
+ fn missing(_input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
+ Ok(ImportTarget::Missing)
}
fn hash(input: ParseInput) -> ParseResult<Hash> {
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 8891d41..5bb987b 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -379,8 +379,8 @@ impl Display for Hash {
impl<SubExpr: Display> Display for Import<SubExpr> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use FilePrefix::*;
- use ImportLocation::*;
use ImportMode::*;
+ use ImportTarget::*;
let quote_if_needed = |s: &str| -> String {
if s.chars().all(|c| c.is_ascii_alphanumeric()) {
s.to_string()
@@ -406,7 +406,7 @@ impl<SubExpr: Display> Display for Import<SubExpr> {
f.write_str(&path)?;
}
Remote(url) => {
- write!(f, "{}://{}/", url.scheme, url.authority,)?;
+ write!(f, "{}://{}/", url.scheme, url.authority)?;
let path: String = url.path.file_path.iter().join("/");
f.write_str(&path)?;
if let Some(q) = &url.query {