From d6fbfc5f6effba8706615cf52536b28abcb91343 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 17 Dec 2019 12:19:17 +0000 Subject: Specialize parsing --- dhall/src/syntax/binary.rs | 1 + dhall/src/syntax/parser.rs | 152 +++++++++++++++++++-------------------------- 2 files changed, 66 insertions(+), 87 deletions(-) diff --git a/dhall/src/syntax/binary.rs b/dhall/src/syntax/binary.rs index 9fe31ad..ad503ef 100644 --- a/dhall/src/syntax/binary.rs +++ b/dhall/src/syntax/binary.rs @@ -20,6 +20,7 @@ pub(crate) fn decode(data: &[u8]) -> Result { } } +/// Warning: will fail if `expr` contains an `Embed` node. pub(crate) fn encode(expr: &Expr) -> Result, EncodeError> { serde_cbor::ser::to_vec(&Serialize::Expr(expr)) .map_err(|e| EncodeError::CBORError(e)) diff --git a/dhall/src/syntax/parser.rs b/dhall/src/syntax/parser.rs index 9aa9403..f6b6577 100644 --- a/dhall/src/syntax/parser.rs +++ b/dhall/src/syntax/parser.rs @@ -5,27 +5,35 @@ 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::*; +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 ParsedText = InterpolatedText>; -type ParsedTextContents = InterpolatedTextContents>; +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 { +enum Selector { Field(Label), Projection(DupTreeSet