diff options
author | Nadrieril | 2019-12-15 20:10:54 +0000 |
---|---|---|
committer | Nadrieril | 2019-12-15 20:10:54 +0000 |
commit | 78e9e32e1357d50313287dd2a3c437132c83aeb6 (patch) | |
tree | 0e7f6172490241f4e413102a6bf7677f2a6d27c1 | |
parent | b11a2cd6ca50d5a4dfa71ae8cd0642fb1c75e1cf (diff) |
Move contents of dhall_syntax to dhall
Diffstat (limited to '')
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | dhall/Cargo.toml | 14 | ||||
-rw-r--r-- | dhall/src/lib.rs | 4 | ||||
-rw-r--r-- | dhall/src/syntax/core/context.rs (renamed from dhall_syntax/src/core/context.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/expr.rs (renamed from dhall_syntax/src/core/expr.rs) | 6 | ||||
-rw-r--r-- | dhall/src/syntax/core/import.rs (renamed from dhall_syntax/src/core/import.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/label.rs (renamed from dhall_syntax/src/core/label.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/map.rs (renamed from dhall_syntax/src/core/map.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/mod.rs (renamed from dhall_syntax/src/core/mod.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/span.rs (renamed from dhall_syntax/src/core/span.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/text.rs (renamed from dhall_syntax/src/core/text.rs) | 0 | ||||
-rw-r--r-- | dhall/src/syntax/core/visitor.rs (renamed from dhall_syntax/src/core/visitor.rs) | 6 | ||||
-rw-r--r-- | dhall/src/syntax/mod.rs | 15 | ||||
-rw-r--r-- | dhall/src/syntax/parser.rs (renamed from dhall_syntax/src/parser.rs) | 28 | ||||
-rw-r--r-- | dhall/src/syntax/printer.rs (renamed from dhall_syntax/src/printer.rs) | 14 | ||||
-rw-r--r-- | dhall_syntax/src/lib.rs | 22 |
16 files changed, 59 insertions, 57 deletions
@@ -74,9 +74,14 @@ name = "dhall" version = "0.1.0" dependencies = [ "bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dhall_syntax 0.1.0", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "improved_slice_patterns 2.0.0", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pest_consume 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml index 16c1c78..2a2a3fe 100644 --- a/dhall/Cargo.toml +++ b/dhall/Cargo.toml @@ -8,13 +8,19 @@ build = "build.rs" [dependencies] bytecount = "0.5.1" +either = "1.5.2" +improved_slice_patterns = { version = "2.0.0", path = "../improved_slice_patterns" } itertools = "0.8.0" -take_mut = "0.2.2" -term-painter = "0.2.3" +hex = "0.3.2" +lazy_static = "1.4.0" +percent-encoding = "2.1.0" +pest = "2.1" +# pest_consume = { path = "../../pest_consume/pest_consume" } +pest_consume = "1.0" serde = { version = "1.0" } serde_cbor = "0.9.0" -improved_slice_patterns = { version = "2.0.0", path = "../improved_slice_patterns" } -dhall_syntax = { path = "../dhall_syntax" } +take_mut = "0.2.2" +term-painter = "0.2.3" [dev-dependencies] pretty_assertions = "0.6.1" diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 86af98f..0991375 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -13,6 +13,4 @@ mod tests; pub mod semantics; -pub mod syntax { - pub use dhall_syntax::*; -} +pub mod syntax; diff --git a/dhall_syntax/src/core/context.rs b/dhall/src/syntax/core/context.rs index 6844baa..6844baa 100644 --- a/dhall_syntax/src/core/context.rs +++ b/dhall/src/syntax/core/context.rs diff --git a/dhall_syntax/src/core/expr.rs b/dhall/src/syntax/core/expr.rs index 131f97e..7972283 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall/src/syntax/core/expr.rs @@ -1,6 +1,6 @@ -use crate::map::{DupTreeMap, DupTreeSet}; -use crate::visitor::{self, ExprFMutVisitor, ExprFVisitor}; -use crate::*; +use crate::syntax::map::{DupTreeMap, DupTreeSet}; +use crate::syntax::visitor::{self, ExprFMutVisitor, ExprFVisitor}; +use crate::syntax::*; pub type Integer = isize; pub type Natural = usize; diff --git a/dhall_syntax/src/core/import.rs b/dhall/src/syntax/core/import.rs index da3e99b..da3e99b 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall/src/syntax/core/import.rs diff --git a/dhall_syntax/src/core/label.rs b/dhall/src/syntax/core/label.rs index 43c3f53..43c3f53 100644 --- a/dhall_syntax/src/core/label.rs +++ b/dhall/src/syntax/core/label.rs diff --git a/dhall_syntax/src/core/map.rs b/dhall/src/syntax/core/map.rs index c4c6126..c4c6126 100644 --- a/dhall_syntax/src/core/map.rs +++ b/dhall/src/syntax/core/map.rs diff --git a/dhall_syntax/src/core/mod.rs b/dhall/src/syntax/core/mod.rs index 66bf229..66bf229 100644 --- a/dhall_syntax/src/core/mod.rs +++ b/dhall/src/syntax/core/mod.rs diff --git a/dhall_syntax/src/core/span.rs b/dhall/src/syntax/core/span.rs index f9c7008..f9c7008 100644 --- a/dhall_syntax/src/core/span.rs +++ b/dhall/src/syntax/core/span.rs diff --git a/dhall_syntax/src/core/text.rs b/dhall/src/syntax/core/text.rs index fb390ee..fb390ee 100644 --- a/dhall_syntax/src/core/text.rs +++ b/dhall/src/syntax/core/text.rs diff --git a/dhall_syntax/src/core/visitor.rs b/dhall/src/syntax/core/visitor.rs index 143e556..b76d037 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall/src/syntax/core/visitor.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::syntax::*; use std::iter::FromIterator; /// A visitor trait that can be used to traverse `ExprF`s. We need this pattern so that Rust lets @@ -111,7 +111,7 @@ where .collect() } - use crate::ExprF::*; + use crate::syntax::ExprF::*; Ok(match input { Var(v) => Var(v.clone()), Lam(l, t, e) => { @@ -225,7 +225,7 @@ where Ok(()) } - use crate::ExprF::*; + use crate::syntax::ExprF::*; match input { Var(_) | Const(_) | Builtin(_) | BoolLit(_) | NaturalLit(_) | IntegerLit(_) | DoubleLit(_) => {} diff --git a/dhall/src/syntax/mod.rs b/dhall/src/syntax/mod.rs new file mode 100644 index 0000000..177c4f1 --- /dev/null +++ b/dhall/src/syntax/mod.rs @@ -0,0 +1,15 @@ +#![allow( + clippy::many_single_char_names, + clippy::should_implement_trait, + clippy::new_without_default, + clippy::type_complexity +)] + +mod core; +pub use crate::syntax::core::context; +pub use crate::syntax::core::visitor; +pub use crate::syntax::core::*; +mod printer; +pub use crate::syntax::printer::*; +mod parser; +pub use crate::syntax::parser::*; diff --git a/dhall_syntax/src/parser.rs b/dhall/src/syntax/parser.rs index 044d3f1..2f589fe 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall/src/syntax/parser.rs @@ -5,9 +5,9 @@ use std::rc::Rc; use pest_consume::{match_nodes, Parser}; -use crate::map::{DupTreeMap, DupTreeSet}; -use crate::ExprF::*; -use crate::*; +use crate::syntax::map::{DupTreeMap, DupTreeSet}; +use crate::syntax::ExprF::*; +use crate::syntax::*; // This file consumes the parse tree generated by pest and turns it into // our own AST. All those custom macros should eventually moved into @@ -28,9 +28,9 @@ enum Selector<E> { ProjectionByExpr(Expr<E>), } -impl crate::Builtin { +impl crate::syntax::Builtin { pub fn parse(s: &str) -> Option<Self> { - use crate::Builtin::*; + use crate::syntax::Builtin::*; match s { "Bool" => Some(Bool), "Natural" => Some(Natural), @@ -146,7 +146,7 @@ lazy_static::lazy_static! { } #[derive(Parser)] -#[grammar = "dhall.pest"] +#[grammar = "../../dhall_syntax/src/dhall.pest"] struct DhallParser; #[pest_consume::parser(parser = DhallParser, rule = Rule)] @@ -328,14 +328,14 @@ impl DhallParser { #[alias(expression)] fn builtin<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { let s = input.as_str(); - let e = match crate::Builtin::parse(s) { + let e = match crate::syntax::Builtin::parse(s) { Some(b) => Builtin(b), None => match s { "True" => BoolLit(true), "False" => BoolLit(false), - "Type" => Const(crate::Const::Type), - "Kind" => Const(crate::Const::Kind), - "Sort" => Const(crate::Const::Sort), + "Type" => Const(crate::syntax::Const::Type), + "Kind" => Const(crate::syntax::Const::Kind), + "Sort" => Const(crate::syntax::Const::Sort), _ => { Err(input.error(format!("Unrecognized builtin: '{}'", s)))? } @@ -575,8 +575,8 @@ impl DhallParser { fn import_hashed<E: Clone>( input: ParseInput, - ) -> ParseResult<crate::Import<Expr<E>>> { - use crate::Import; + ) -> ParseResult<crate::syntax::Import<Expr<E>>> { + use crate::syntax::Import; let mode = ImportMode::Code; Ok(match_nodes!(input.into_children(); [import_type(location)] => Import { mode, location, hash: None }, @@ -595,7 +595,7 @@ impl DhallParser { #[alias(expression)] fn import<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { - use crate::Import; + use crate::syntax::Import; let import = match_nodes!(input.children(); [import_hashed(imp)] => { Import { mode: ImportMode::Code, ..imp } @@ -699,7 +699,7 @@ impl DhallParser { op: ParseInput, r: Expr<E>, ) -> ParseResult<Expr<E>> { - use crate::BinOp::*; + use crate::syntax::BinOp::*; use Rule::*; let op = match op.as_rule() { import_alt => ImportAlt, diff --git a/dhall_syntax/src/printer.rs b/dhall/src/syntax/printer.rs index ce6ff97..8df456b 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall/src/syntax/printer.rs @@ -1,11 +1,11 @@ -use crate::*; +use crate::syntax::*; use itertools::Itertools; use std::fmt::{self, Display}; /// Generic instance that delegates to subexpressions impl<SE: Display + Clone, E: Display> Display for ExprF<SE, E> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use crate::ExprF::*; + use crate::syntax::ExprF::*; match self { Lam(a, b, c) => { write!(f, "λ({} : {}) → {}", a, b, c)?; @@ -141,7 +141,7 @@ impl<A: Display + Clone> RawExpr<A> { f: &mut fmt::Formatter, phase: PrintPhase, ) -> Result<(), fmt::Error> { - use crate::ExprF::*; + use crate::syntax::ExprF::*; use PrintPhase::*; let needs_paren = match self { @@ -298,7 +298,7 @@ impl Display for Const { impl Display for BinOp { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use crate::BinOp::*; + use crate::syntax::BinOp::*; f.write_str(match self { BoolOr => "||", TextAppend => "++", @@ -344,7 +344,7 @@ impl Display for Label { let is_reserved = match s.as_str() { "let" | "in" | "if" | "then" | "else" | "Type" | "Kind" | "Sort" | "True" | "False" => true, - _ => crate::Builtin::parse(&s).is_some(), + _ => crate::syntax::Builtin::parse(&s).is_some(), }; if !is_reserved && s.chars().all(|c| c.is_ascii_alphanumeric()) { write!(f, "{}", s) @@ -443,7 +443,7 @@ impl<SubExpr: Display> Display for Import<SubExpr> { impl Display for Builtin { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use crate::Builtin::*; + use crate::syntax::Builtin::*; f.write_str(match *self { Bool => "Bool", Natural => "Natural", @@ -480,7 +480,7 @@ impl Display for Builtin { impl Display for Scheme { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use crate::Scheme::*; + use crate::syntax::Scheme::*; f.write_str(match *self { HTTP => "http", HTTPS => "https", diff --git a/dhall_syntax/src/lib.rs b/dhall_syntax/src/lib.rs index b8fa19f..e69de29 100644 --- a/dhall_syntax/src/lib.rs +++ b/dhall_syntax/src/lib.rs @@ -1,22 +0,0 @@ -#![feature(trace_macros)] -#![feature(never_type)] -#![allow( - clippy::many_single_char_names, - clippy::should_implement_trait, - clippy::new_without_default, - clippy::type_complexity -)] - -//! This crate contains the core AST-handling primitives for the [dhall-rust][dhall-rust] crate. -//! This is highly unstable and breaks regularly; use at your own risk. -//! -//! [dhall-rust]: https://github.com/Nadrieril/dhall-rust - -mod core; -pub use crate::core::context; -pub use crate::core::visitor; -pub use crate::core::*; -mod printer; -pub use crate::printer::*; -mod parser; -pub use crate::parser::*; |