From 47e763c3ee4c1a07b51c68854cd2d48288b65056 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 17 Dec 2019 12:24:14 +0000 Subject: Split syntax module between text and binary --- dhall/src/syntax/text/mod.rs | 2 + dhall/src/syntax/text/parser.rs | 920 +++++++++++++++++++++++++++++++++++++++ dhall/src/syntax/text/printer.rs | 500 +++++++++++++++++++++ 3 files changed, 1422 insertions(+) create mode 100644 dhall/src/syntax/text/mod.rs create mode 100644 dhall/src/syntax/text/parser.rs create mode 100644 dhall/src/syntax/text/printer.rs (limited to 'dhall/src/syntax/text') diff --git a/dhall/src/syntax/text/mod.rs b/dhall/src/syntax/text/mod.rs new file mode 100644 index 0000000..c868288 --- /dev/null +++ b/dhall/src/syntax/text/mod.rs @@ -0,0 +1,2 @@ +pub mod parser; +pub mod printer; diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs new file mode 100644 index 0000000..f6b6577 --- /dev/null +++ b/dhall/src/syntax/text/parser.rs @@ -0,0 +1,920 @@ +use itertools::Itertools; +use pest::prec_climber as pcl; +use pest::prec_climber::PrecClimber; +use std::rc::Rc; + +use pest_consume::{match_nodes, Parser}; + +use crate::semantics::phase::Normalized; +use crate::syntax; +use crate::syntax::core; +use crate::syntax::map::{DupTreeMap, DupTreeSet}; +use crate::syntax::ExprF::*; +use crate::syntax::{ + FilePath, FilePrefix, Hash, ImportLocation, ImportMode, InterpolatedText, + InterpolatedTextContents, Label, NaiveDouble, RawExpr, Scheme, Span, URL, + V, +}; + +// This file consumes the parse tree generated by pest and turns it into +// our own AST. All those custom macros should eventually moved into +// their own crate because they are quite general and useful. For now they +// are here and hopefully you can figure out how they work. + +type Expr = syntax::Expr; +type ParsedText = InterpolatedText; +type ParsedTextContents = InterpolatedTextContents; +type ParseInput<'input> = pest_consume::Node<'input, Rule, Rc>; + +pub type ParseError = pest::error::Error; +pub type ParseResult = Result; + +#[derive(Debug)] +enum Selector { + Field(Label), + Projection(DupTreeSet