summaryrefslogtreecommitdiff
path: root/dhall_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'dhall_syntax/src')
-rw-r--r--dhall_syntax/src/core/import.rs5
-rw-r--r--dhall_syntax/src/parser.rs19
-rw-r--r--dhall_syntax/src/printer.rs4
3 files changed, 19 insertions, 9 deletions
diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs
index fbf2f7b..c328e34 100644
--- a/dhall_syntax/src/core/import.rs
+++ b/dhall_syntax/src/core/import.rs
@@ -43,9 +43,8 @@ pub enum ImportMode {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct Hash {
- pub protocol: String,
- pub hash: String,
+pub enum Hash {
+ SHA256(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 316ef2f..9d9a374 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -461,6 +461,11 @@ make_parser! {
lines.push(vec![]);
lines
},
+ [single_quote_char("\r\n"), single_quote_continue(lines)] => {
+ let mut lines = lines;
+ lines.push(vec![]);
+ lines
+ },
[single_quote_char(c), single_quote_continue(lines)] => {
// TODO: don't allocate for every char
let c = InterpolatedTextContents::Text(c.to_owned());
@@ -654,12 +659,15 @@ make_parser! {
},
));
- rule!(hash<Hash>; captured_str!(s) =>
- Hash {
- protocol: s.trim()[..6].to_owned(),
- hash: s.trim()[7..].to_owned(),
+ rule!(hash<Hash>; captured_str!(s) => {
+ let s = s.trim();
+ let protocol = &s[..6];
+ let hash = &s[7..];
+ if protocol != "sha256" {
+ Err(format!("Unknown hashing protocol '{}'", protocol))?
}
- );
+ Hash::SHA256(hex::decode(hash).unwrap())
+ });
rule!(import_hashed<ImportHashed>; children!(
[import_type(location)] =>
@@ -870,6 +878,7 @@ make_parser! {
rule!(selector<Either<Label, Vec<Label>>>; children!(
[label(l)] => Either::Left(l),
[labels(ls)] => Either::Right(ls),
+ [expression(e)] => unimplemented!("selection by expression"), // TODO
));
rule!(labels<Vec<Label>>; children!(
diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs
index f1ce230..dbed55d 100644
--- a/dhall_syntax/src/printer.rs
+++ b/dhall_syntax/src/printer.rs
@@ -348,7 +348,9 @@ impl Display for Label {
impl Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- write!(f, "{}:{}", self.protocol, self.hash)
+ match self {
+ Hash::SHA256(hash) => write!(f, "sha256:{}", hex::encode(hash)),
+ }
}
}
impl Display for ImportHashed {