summaryrefslogtreecommitdiff
path: root/dhall/src/syntax
diff options
context:
space:
mode:
authorNadrieril2020-04-05 17:57:07 +0100
committerGitHub2020-04-05 17:57:07 +0100
commit7e977f282fb6a0eff0ef45738b9b5c98dc4c6fee (patch)
treead4249609707fd8720a44469152105c2f6a67c79 /dhall/src/syntax
parent5a5aa49e64197899006751db72e404f4b2292d4e (diff)
parent820214615547101f8f2b5de209b5189968bddfee (diff)
Merge pull request #154 from Nadrieril/cleanup-api
Rewrite serde_dhall API
Diffstat (limited to 'dhall/src/syntax')
-rw-r--r--dhall/src/syntax/ast/expr.rs16
-rw-r--r--dhall/src/syntax/ast/mod.rs2
-rw-r--r--dhall/src/syntax/ast/span.rs12
-rw-r--r--dhall/src/syntax/ast/visitor.rs4
-rw-r--r--dhall/src/syntax/binary/decode.rs20
-rw-r--r--dhall/src/syntax/binary/encode.rs12
-rw-r--r--dhall/src/syntax/binary/mod.rs4
-rw-r--r--dhall/src/syntax/text/parser.rs14
-rw-r--r--dhall/src/syntax/text/printer.rs6
9 files changed, 45 insertions, 45 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index b53e6cb..6ba6649 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -22,7 +22,7 @@ pub enum Const {
}
impl Const {
- pub(crate) fn to_universe(self) -> Universe {
+ pub fn to_universe(self) -> Universe {
Universe::from_const(self)
}
}
@@ -112,9 +112,9 @@ pub struct Expr {
pub type UnspannedExpr = ExprKind<Expr>;
-/// Simple literals
+/// Numeric literals
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub enum LitKind {
+pub enum NumKind {
/// `True`
Bool(bool),
/// `1`
@@ -132,7 +132,7 @@ pub enum LitKind {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExprKind<SubExpr> {
Const(Const),
- Lit(LitKind),
+ Num(NumKind),
/// `x`
/// `x@n`
Var(V),
@@ -205,7 +205,7 @@ impl<SE> ExprKind<SE> {
})
}
- pub(crate) fn traverse_ref<'a, SE2, Err>(
+ pub fn traverse_ref<'a, SE2, Err>(
&'a self,
mut visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
) -> Result<ExprKind<SE2>, Err> {
@@ -239,17 +239,17 @@ impl<SE> ExprKind<SE> {
}
impl Expr {
- pub(crate) fn as_ref(&self) -> &UnspannedExpr {
+ pub fn as_ref(&self) -> &UnspannedExpr {
&self.kind
}
pub fn kind(&self) -> &UnspannedExpr {
&self.kind
}
- pub(crate) fn span(&self) -> Span {
+ pub fn span(&self) -> Span {
self.span.clone()
}
- pub(crate) fn new(kind: UnspannedExpr, span: Span) -> Self {
+ pub fn new(kind: UnspannedExpr, span: Span) -> Self {
Expr {
kind: Box::new(kind),
span,
diff --git a/dhall/src/syntax/ast/mod.rs b/dhall/src/syntax/ast/mod.rs
index 5e20c5d..1950154 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(crate) use span::*;
+pub 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 2e09863..e250602 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(crate) struct ParsedSpan {
+pub struct ParsedSpan {
input: Rc<str>,
/// # Safety
///
@@ -15,7 +15,7 @@ pub(crate) struct ParsedSpan {
}
#[derive(Debug, Clone)]
-pub(crate) enum Span {
+pub enum Span {
/// A location in the source text
Parsed(ParsedSpan),
/// Desugarings
@@ -30,12 +30,12 @@ pub(crate) enum Span {
}
impl ParsedSpan {
- pub(crate) fn to_input(&self) -> String {
+ pub fn to_input(&self) -> String {
self.input.to_string()
}
/// Convert to a char range for consumption by annotate_snippets.
/// This compensates for https://github.com/rust-lang/annotate-snippets-rs/issues/24
- pub(crate) fn as_char_range(&self) -> (usize, usize) {
+ pub fn as_char_range(&self) -> (usize, usize) {
(
char_idx_from_byte_idx(&self.input, self.start),
char_idx_from_byte_idx(&self.input, self.end),
@@ -44,7 +44,7 @@ impl ParsedSpan {
}
impl Span {
- pub(crate) fn make(input: Rc<str>, sp: pest::Span) -> Self {
+ pub fn make(input: Rc<str>, sp: pest::Span) -> Self {
Span::Parsed(ParsedSpan {
input,
start: sp.start(),
@@ -55,7 +55,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(crate) fn union(&self, other: &Span) -> Self {
+ pub fn union(&self, other: &Span) -> Self {
use std::cmp::{max, min};
use Span::*;
match (self, other) {
diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs
index c361bc1..0a0c5ef 100644
--- a/dhall/src/syntax/ast/visitor.rs
+++ b/dhall/src/syntax/ast/visitor.rs
@@ -51,7 +51,7 @@ where
.collect()
}
-pub(crate) fn visit_ref<'a, F, SE1, SE2, Err>(
+pub fn visit_ref<'a, F, SE1, SE2, Err>(
input: &'a ExprKind<SE1>,
mut f: F,
) -> Result<ExprKind<SE2>, Err>
@@ -91,7 +91,7 @@ where
Annot(x, t) => Annot(expr!(x)?, expr!(t)?),
Const(k) => Const(*k),
Builtin(v) => Builtin(*v),
- Lit(l) => Lit(l.clone()),
+ Num(n) => Num(n.clone()),
TextLit(t) => TextLit(t.traverse_ref(|e| expr!(e))?),
BinOp(o, x, y) => BinOp(*o, expr!(x)?, expr!(y)?),
BoolIf(b, t, f) => BoolIf(expr!(b)?, expr!(t)?, expr!(f)?),
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index 2ecd7e0..3c93419 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -6,12 +6,12 @@ use crate::error::DecodeError;
use crate::syntax;
use crate::syntax::{
Expr, ExprKind, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
- Integer, InterpolatedText, Label, LitKind, Natural, Scheme, Span,
+ Integer, InterpolatedText, Label, Natural, NumKind, Scheme, Span,
UnspannedExpr, URL, V,
};
-use crate::DecodedExpr;
+type DecodedExpr = Expr;
-pub(crate) fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> {
+pub fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> {
match serde_cbor::de::from_slice(data) {
Ok(v) => cbor_value_to_dhall(&v),
Err(e) => Err(DecodeError::CBORError(e)),
@@ -31,8 +31,8 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
String(s) => match Builtin::parse(s) {
Some(b) => ExprKind::Builtin(b),
None => match s.as_str() {
- "True" => Lit(LitKind::Bool(true)),
- "False" => Lit(LitKind::Bool(false)),
+ "True" => Num(NumKind::Bool(true)),
+ "False" => Num(NumKind::Bool(false)),
"Type" => Const(Const::Type),
"Kind" => Const(Const::Kind),
"Sort" => Const(Const::Sort),
@@ -44,8 +44,8 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
},
},
U64(n) => Var(V(Label::from("_"), *n as usize)),
- F64(x) => Lit(LitKind::Double((*x).into())),
- Bool(b) => Lit(LitKind::Bool(*b)),
+ F64(x) => Num(NumKind::Double((*x).into())),
+ Bool(b) => Num(NumKind::Bool(*b)),
Array(vec) => match vec.as_slice() {
[String(l), U64(n)] => {
if l.as_str() == "_" {
@@ -224,9 +224,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let z = cbor_value_to_dhall(&z)?;
BoolIf(x, y, z)
}
- [U64(15), U64(x)] => Lit(LitKind::Natural(*x as Natural)),
- [U64(16), U64(x)] => Lit(LitKind::Integer(*x as Integer)),
- [U64(16), I64(x)] => Lit(LitKind::Integer(*x as Integer)),
+ [U64(15), U64(x)] => Num(NumKind::Natural(*x as Natural)),
+ [U64(16), U64(x)] => Num(NumKind::Integer(*x as Integer)),
+ [U64(16), I64(x)] => Num(NumKind::Integer(*x as Integer)),
[U64(18), String(first), rest @ ..] => {
TextLit(InterpolatedText::from((
first.clone(),
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index 9e6948e..8d22a9b 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -10,7 +10,7 @@ use crate::syntax::{
Scheme, V,
};
-pub(crate) fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
+pub fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
serde_cbor::ser::to_vec(&Serialize::Expr(expr))
.map_err(EncodeError::CBORError)
}
@@ -48,7 +48,7 @@ where
use std::iter::once;
use syntax::Builtin;
use syntax::ExprKind::*;
- use syntax::LitKind::*;
+ use syntax::NumKind::*;
use self::Serialize::{RecordDupMap, RecordMap, UnionMap};
fn expr(x: &Expr) -> self::Serialize<'_> {
@@ -63,10 +63,10 @@ where
match e.as_ref() {
Const(c) => ser.serialize_str(&c.to_string()),
Builtin(b) => ser.serialize_str(&b.to_string()),
- Lit(Bool(b)) => ser.serialize_bool(*b),
- Lit(Natural(n)) => ser_seq!(ser; tag(15), U64(*n as u64)),
- Lit(Integer(n)) => ser_seq!(ser; tag(16), I64(*n as i64)),
- Lit(Double(n)) => {
+ Num(Bool(b)) => ser.serialize_bool(*b),
+ Num(Natural(n)) => ser_seq!(ser; tag(15), U64(*n as u64)),
+ Num(Integer(n)) => ser_seq!(ser; tag(16), I64(*n as i64)),
+ Num(Double(n)) => {
let n: f64 = (*n).into();
ser.serialize_f64(n)
}
diff --git a/dhall/src/syntax/binary/mod.rs b/dhall/src/syntax/binary/mod.rs
index 7ed1f6e..98e0520 100644
--- a/dhall/src/syntax/binary/mod.rs
+++ b/dhall/src/syntax/binary/mod.rs
@@ -1,4 +1,4 @@
mod decode;
mod encode;
-pub(crate) use decode::decode;
-pub(crate) use encode::encode;
+pub use decode::decode;
+pub use encode::encode;
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index 03211c7..6f5949f 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -9,7 +9,7 @@ use pest_consume::{match_nodes, Parser};
use crate::syntax::map::{DupTreeMap, DupTreeSet};
use crate::syntax::ExprKind::*;
-use crate::syntax::LitKind::*;
+use crate::syntax::NumKind::*;
use crate::syntax::{
Double, Expr, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
Integer, InterpolatedText, InterpolatedTextContents, Label, NaiveDouble,
@@ -135,7 +135,7 @@ fn insert_recordlit_entry(map: &mut BTreeMap<Label, Expr>, l: Label, e: Expr) {
entry.insert(e);
}
Entry::Occupied(mut entry) => {
- let dummy = Expr::new(Lit(Bool(false)), Span::Artificial);
+ let dummy = Expr::new(Num(Bool(false)), Span::Artificial);
let other = entry.insert(dummy);
entry.insert(Expr::new(
BinOp(RecursiveRecordMerge, other, e),
@@ -390,8 +390,8 @@ impl DhallParser {
let e = match crate::syntax::Builtin::parse(s) {
Some(b) => Builtin(b),
None => match s {
- "True" => Lit(Bool(true)),
- "False" => Lit(Bool(false)),
+ "True" => Num(Bool(true)),
+ "False" => Num(Bool(false)),
"Type" => Const(crate::syntax::Const::Type),
"Kind" => Const(crate::syntax::Const::Kind),
"Sort" => Const(crate::syntax::Const::Sort),
@@ -924,9 +924,9 @@ impl DhallParser {
#[alias(expression, shortcut = true)]
fn primitive_expression(input: ParseInput) -> ParseResult<Expr> {
Ok(match_nodes!(input.children();
- [double_literal(n)] => spanned(input, Lit(Double(n))),
- [natural_literal(n)] => spanned(input, Lit(Natural(n))),
- [integer_literal(n)] => spanned(input, Lit(Integer(n))),
+ [double_literal(n)] => spanned(input, Num(Double(n))),
+ [natural_literal(n)] => spanned(input, Num(Natural(n))),
+ [integer_literal(n)] => spanned(input, Num(Integer(n))),
[double_quote_literal(s)] => spanned(input, TextLit(s)),
[single_quote_literal(s)] => spanned(input, TextLit(s)),
[record_type_or_literal(e)] => spanned(input, e),
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 2b7bc2e..378f408 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -201,7 +201,7 @@ impl<SE: Display + Clone> Display for ExprKind<SE> {
Var(a) => a.fmt(f)?,
Const(k) => k.fmt(f)?,
Builtin(v) => v.fmt(f)?,
- Lit(a) => a.fmt(f)?,
+ Num(a) => a.fmt(f)?,
TextLit(a) => a.fmt(f)?,
RecordType(a) if a.is_empty() => f.write_str("{}")?,
RecordType(a) => fmt_list("{ ", ", ", " }", a, f, |(k, t), f| {
@@ -240,9 +240,9 @@ impl Display for Expr {
}
}
-impl Display for LitKind {
+impl Display for NumKind {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- use LitKind::*;
+ use NumKind::*;
match self {
Bool(true) => f.write_str("True")?,
Bool(false) => f.write_str("False")?,