From d86a5e8a1f469dd79abf3137dba77a71fae2a774 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 3 Feb 2021 21:30:36 +0100 Subject: =?UTF-8?q?Tidy=20up=20raw=20blocks=20=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Better trimming (only trim at the end if necessary) - Fixed block-level layouting - Improved pretty printing - Flip inline variable to block - Flip inline variable to display for math formulas --- src/eval/mod.rs | 12 ++++++++++-- src/eval/value.rs | 30 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'src/eval') diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 1a211670..4f8961cc 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -142,6 +142,10 @@ impl Eval for Spanned<&NodeRaw> { })); } + if self.v.block { + ctx.apply_parbreak(); + } + ctx.push(NodeStack { dirs: ctx.state.dirs, align: ctx.state.align, @@ -149,6 +153,10 @@ impl Eval for Spanned<&NodeRaw> { children, }); + if self.v.block { + ctx.apply_parbreak(); + } + ctx.state.font.families = prev; } } @@ -466,8 +474,8 @@ impl Eval for Spanned<&ExprFor> { iterate!(for (k => key, v => value) in dict.into_iter()) } - (ForPattern::KeyValue(..), Value::Str(_)) - | (ForPattern::KeyValue(..), Value::Array(_)) => { + (ForPattern::KeyValue(_, _), Value::Str(_)) + | (ForPattern::KeyValue(_, _), Value::Array(_)) => { ctx.diag(error!(self.v.pat.span, "mismatched pattern")); Value::Error } diff --git a/src/eval/value.rs b/src/eval/value.rs index 860c0634..119a2f1b 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -110,15 +110,15 @@ impl Pretty for Value { fn pretty(&self, p: &mut Printer) { match self { Value::None => p.push_str("none"), - Value::Bool(v) => write!(p, "{}", v).unwrap(), - Value::Int(v) => p.push_str(itoa::Buffer::new().format(*v)), - Value::Float(v) => p.push_str(ryu::Buffer::new().format(*v)), - Value::Length(v) => write!(p, "{}", v).unwrap(), - Value::Angle(v) => write!(p, "{}", v).unwrap(), - Value::Relative(v) => write!(p, "{}", v).unwrap(), - Value::Linear(v) => write!(p, "{}", v).unwrap(), - Value::Color(v) => write!(p, "{}", v).unwrap(), - Value::Str(v) => write!(p, "{:?}", v).unwrap(), + Value::Bool(v) => v.pretty(p), + Value::Int(v) => v.pretty(p), + Value::Float(v) => v.pretty(p), + Value::Length(v) => v.pretty(p), + Value::Angle(v) => v.pretty(p), + Value::Relative(v) => v.pretty(p), + Value::Linear(v) => v.pretty(p), + Value::Color(v) => v.pretty(p), + Value::Str(v) => v.pretty(p), Value::Array(v) => v.pretty(p), Value::Dict(v) => v.pretty(p), Value::Template(v) => pretty_template(v, p), @@ -134,12 +134,12 @@ pub type ValueArray = Vec; impl Pretty for ValueArray { fn pretty(&self, p: &mut Printer) { - p.push_str("("); + p.push('('); p.join(self, ", ", |item, p| item.pretty(p)); if self.len() == 1 { - p.push_str(","); + p.push(','); } - p.push_str(")"); + p.push(')'); } } @@ -148,9 +148,9 @@ pub type ValueDict = BTreeMap; impl Pretty for ValueDict { fn pretty(&self, p: &mut Printer) { - p.push_str("("); + p.push('('); if self.is_empty() { - p.push_str(":"); + p.push(':'); } else { p.join(self, ", ", |(key, value), p| { p.push_str(key); @@ -158,7 +158,7 @@ impl Pretty for ValueDict { value.pretty(p); }); } - p.push_str(")"); + p.push(')'); } } -- cgit v1.2.3