summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanoTech2016-12-11 20:23:33 -0600
committerNanoTech2017-03-10 23:48:29 -0600
commitb21c60471614d516b046a206090c03b91da4604e (patch)
tree6755fbfa6056294544274d6212156967013f08a8
parentf1317bfef6131d78fd518b1e749fbae5327f8384 (diff)
Format ListLit and OptionalLit
Diffstat (limited to '')
-rw-r--r--src/core.rs50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/core.rs b/src/core.rs
index 3afddb5..9758830 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -342,8 +342,14 @@ impl<'i, S, A: Display> Expr<'i, S, A> {
write!(f, ") → ")?;
d.fmt_b(f)
}
- &ListLit(_, _) => f.write_str("ListLit"),
- &OptionalLit(_, _) => f.write_str("OptionalLit"),
+ &ListLit(ref t, ref es) => {
+ fmt_list("[", "] : List ", es, f, |e, f| e.fmt(f))?;
+ t.fmt_e(f)
+ }
+ &OptionalLit(ref t, ref es) => {
+ fmt_list("[", "] : Optional ", es, f, |e, f| e.fmt(f))?;
+ t.fmt_e(f)
+ }
&Merge(ref a, ref b, ref c) => {
write!(f, "merge ")?;
a.fmt_e(f)?;
@@ -388,27 +394,6 @@ impl<'i, S, A: Display> Expr<'i, S, A> {
fn fmt_f(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use Expr::*;
- fn fmt_list<T,
- I: IntoIterator<Item = T>,
- F: Fn(T, &mut fmt::Formatter) -> Result<(), fmt::Error>>
- (open: &str,
- close: &str,
- it: I,
- f: &mut fmt::Formatter,
- func: F)
- -> Result<(), fmt::Error>
- where I: IntoIterator<Item = T>,
- F: Fn(T, &mut fmt::Formatter) -> Result<(), fmt::Error>
- {
- f.write_str(open)?;
- for (i, x) in it.into_iter().enumerate() {
- if i > 0 {
- f.write_str(", ")?;
- }
- func(x, f)?;
- }
- f.write_str(close)
- }
match self {
&Var(a) => a.fmt(f),
&Const(k) => k.fmt(f),
@@ -440,6 +425,25 @@ impl<'i, S, A: Display> Expr<'i, S, A> {
}
}
+fn fmt_list<T, I, F>(open: &str,
+ close: &str,
+ it: I,
+ f: &mut fmt::Formatter,
+ func: F)
+ -> Result<(), fmt::Error>
+ where I: IntoIterator<Item = T>,
+ F: Fn(T, &mut fmt::Formatter) -> Result<(), fmt::Error>
+{
+ f.write_str(open)?;
+ for (i, x) in it.into_iter().enumerate() {
+ if i > 0 {
+ f.write_str(", ")?;
+ }
+ func(x, f)?;
+ }
+ f.write_str(close)
+}
+
impl Display for Const {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
<Self as fmt::Debug>::fmt(self, f)