summaryrefslogtreecommitdiff
path: root/dhall_core/src/parser.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-14 21:53:07 +0100
committerNadrieril2019-03-14 21:53:07 +0100
commitbc1c40d670de0e37edf525fccd13a837b5983e7e (patch)
tree1f928e89339a6c25a5b0a60a4a563b8cce01a87c /dhall_core/src/parser.rs
parent8c34c3bbc2fc520cce78fd445bdbc3192ce91abf (diff)
Handle and parse interpolated strings
Closes #25
Diffstat (limited to '')
-rw-r--r--dhall_core/src/parser.rs43
1 files changed, 27 insertions, 16 deletions
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs
index 57dd151..ddf3f8f 100644
--- a/dhall_core/src/parser.rs
+++ b/dhall_core/src/parser.rs
@@ -14,6 +14,8 @@ use crate::core::*;
// are here and hopefully you can figure out how they work.
pub type ParsedExpr = Expr<X, Import>;
+pub type ParsedText = InterpolatedText<X, Import>;
+pub type ParsedTextContents<'a> = OwnedInterpolatedTextContents<'a, X, Import>;
pub type BoxExpr = Box<ParsedExpr>;
pub type ParseError = pest::error::Error<Rule>;
@@ -426,17 +428,25 @@ named!(raw_str<&'a str>; captured_str!(s) => s);
named!(label<Label>; captured_str!(s) => Label::from(s.trim().to_owned()));
-// TODO: parse escapes and interpolation
-rule!(double_quote_literal<String>;
- children!(strs*: raw_str) => {
- strs.collect()
+rule!(double_quote_literal<ParsedText>;
+ children!(chunks*: double_quote_chunk) => {
+ chunks.collect()
}
);
-rule!(single_quote_literal<String>;
+// TODO: parse escapes
+rule!(double_quote_chunk<ParsedTextContents<'a>>;
+ children!(c: interpolation) => {
+ OwnedInterpolatedTextContents::Expr(*c)
+ },
+ captured_str!(s) => {
+ OwnedInterpolatedTextContents::Text(s)
+ },
+);
+
+rule!(single_quote_literal<ParsedText>;
children!(eol: raw_str, contents: single_quote_continue) => {
- contents.push(eol);
- contents.into_iter().rev().collect()
+ contents.into_iter().rev().collect::<ParsedText>()
}
);
rule!(escaped_quote_pair<&'a str>;
@@ -445,21 +455,22 @@ rule!(escaped_quote_pair<&'a str>;
rule!(escaped_interpolation<&'a str>;
children!() => "${"
);
+rule!(interpolation<BoxExpr>;
+ children!(e: expression) => e
+);
-rule!(single_quote_continue<Vec<&'a str>>;
- // TODO: handle interpolation
- // children!(c: expression, rest: single_quote_continue) => {
- // rest.push(c); rest
- // },
+rule!(single_quote_continue<Vec<ParsedTextContents<'a>>>;
+ children!(c: interpolation, rest: single_quote_continue) => {
+ rest.push(OwnedInterpolatedTextContents::Expr(*c)); rest
+ },
children!(c: escaped_quote_pair, rest: single_quote_continue) => {
- rest.push(c); rest
+ rest.push(OwnedInterpolatedTextContents::Text(c)); rest
},
children!(c: escaped_interpolation, rest: single_quote_continue) => {
- rest.push(c); rest
+ rest.push(OwnedInterpolatedTextContents::Text(c)); rest
},
- // capture interpolation as string
children!(c: raw_str, rest: single_quote_continue) => {
- rest.push(c); rest
+ rest.push(OwnedInterpolatedTextContents::Text(c)); rest
},
children!() => {
vec![]