summaryrefslogtreecommitdiff
path: root/src/eval/walk.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-08 13:08:15 +0100
committerGitHub <noreply@github.com>2021-11-08 13:08:15 +0100
commitc6f8ad35f45248f1fd36ee00195966f1629c6ca7 (patch)
tree51faa3f6bbc56f75636823adeea135ed76e1b33b /src/eval/walk.rs
parentea6ee3f667e922ed2f21b08719a45d2395787932 (diff)
parent38c5c362419c5eee7a4fdc0b43d3a9dfb339a6d2 (diff)
Merge pull request #46 from typst/parser-ng
Next Generation Parser
Diffstat (limited to 'src/eval/walk.rs')
-rw-r--r--src/eval/walk.rs41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/eval/walk.rs b/src/eval/walk.rs
index 96138338..aab32f40 100644
--- a/src/eval/walk.rs
+++ b/src/eval/walk.rs
@@ -5,7 +5,7 @@ use crate::diag::TypResult;
use crate::geom::Spec;
use crate::layout::BlockLevel;
use crate::library::{GridNode, ParChild, ParNode, TrackSizing};
-use crate::syntax::*;
+use crate::syntax::ast::*;
use crate::util::BoolExt;
/// Walk markup, filling the currently built template.
@@ -16,7 +16,7 @@ pub trait Walk {
impl Walk for Markup {
fn walk(&self, ctx: &mut EvalContext) -> TypResult<()> {
- for node in self.iter() {
+ for node in self.nodes() {
node.walk(ctx)?;
}
Ok(())
@@ -27,12 +27,13 @@ impl Walk for MarkupNode {
fn walk(&self, ctx: &mut EvalContext) -> TypResult<()> {
match self {
Self::Space => ctx.template.space(),
- Self::Linebreak(_) => ctx.template.linebreak(),
- Self::Parbreak(_) => ctx.template.parbreak(),
- Self::Strong(_) => ctx.template.modify(|s| s.text_mut().strong.flip()),
- Self::Emph(_) => ctx.template.modify(|s| s.text_mut().emph.flip()),
+ Self::Linebreak => ctx.template.linebreak(),
+ Self::Parbreak => ctx.template.parbreak(),
+ Self::Strong => ctx.template.modify(|s| s.text_mut().strong.flip()),
+ Self::Emph => ctx.template.modify(|s| s.text_mut().emph.flip()),
Self::Text(text) => ctx.template.text(text),
Self::Raw(raw) => raw.walk(ctx)?,
+ Self::Math(math) => math.walk(ctx)?,
Self::Heading(heading) => heading.walk(ctx)?,
Self::List(list) => list.walk(ctx)?,
Self::Enum(enum_) => enum_.walk(ctx)?,
@@ -67,16 +68,32 @@ impl Walk for RawNode {
}
}
+impl Walk for MathNode {
+ fn walk(&self, ctx: &mut EvalContext) -> TypResult<()> {
+ if self.display {
+ ctx.template.parbreak();
+ }
+
+ ctx.template.monospace(self.formula.trim());
+
+ if self.display {
+ ctx.template.parbreak();
+ }
+
+ Ok(())
+ }
+}
+
impl Walk for HeadingNode {
fn walk(&self, ctx: &mut EvalContext) -> TypResult<()> {
- let level = self.level;
- let body = self.body.eval(ctx)?;
+ let level = self.level();
+ let body = self.body().eval(ctx)?;
ctx.template.parbreak();
ctx.template.save();
ctx.template.modify(move |style| {
let text = style.text_mut();
- let upscale = 1.6 - 0.1 * level as f64;
+ let upscale = (1.6 - 0.1 * level as f64).max(0.75);
text.size *= upscale;
text.strong = true;
});
@@ -90,7 +107,7 @@ impl Walk for HeadingNode {
impl Walk for ListNode {
fn walk(&self, ctx: &mut EvalContext) -> TypResult<()> {
- let body = self.body.eval(ctx)?;
+ let body = self.body().eval(ctx)?;
walk_item(ctx, Str::from('•'), body);
Ok(())
}
@@ -98,8 +115,8 @@ impl Walk for ListNode {
impl Walk for EnumNode {
fn walk(&self, ctx: &mut EvalContext) -> TypResult<()> {
- let body = self.body.eval(ctx)?;
- let label = format_str!("{}.", self.number.unwrap_or(1));
+ let body = self.body().eval(ctx)?;
+ let label = format_str!("{}.", self.number().unwrap_or(1));
walk_item(ctx, label, body);
Ok(())
}