summaryrefslogtreecommitdiff
path: root/src/model/realize.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-02 13:17:07 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-02 13:21:36 +0100
commit5110a41de1ca2236739ace2d37a1af912bb029f1 (patch)
tree22cc223140052bd7ec10798f5ecbffaae7c934a8 /src/model/realize.rs
parent33ab1fdbdda4e95e48b767a3f7f8f66413b6de0e (diff)
Introduce virtual typesetter
Diffstat (limited to 'src/model/realize.rs')
-rw-r--r--src/model/realize.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/model/realize.rs b/src/model/realize.rs
index 9d7c4aec..46e0d678 100644
--- a/src/model/realize.rs
+++ b/src/model/realize.rs
@@ -1,8 +1,5 @@
-use comemo::Tracked;
-
-use super::{capability, Content, NodeId, Recipe, Selector, StyleChain};
+use super::{capability, Content, NodeId, Recipe, Selector, StyleChain, Vt};
use crate::diag::SourceResult;
-use crate::World;
/// Whether the target is affected by show rules in the given style chain.
pub fn applicable(target: &Content, styles: StyleChain) -> bool {
@@ -22,7 +19,7 @@ pub fn applicable(target: &Content, styles: StyleChain) -> bool {
/// Apply the show rules in the given style chain to a target.
pub fn realize(
- world: Tracked<dyn World>,
+ vt: &mut Vt,
target: &Content,
styles: StyleChain,
) -> SourceResult<Option<Content>> {
@@ -34,7 +31,7 @@ pub fn realize(
for recipe in styles.recipes() {
let guard = Guard::Nth(n);
if recipe.applicable(target) && !target.is_guarded(guard) {
- if let Some(content) = try_apply(world, &target, recipe, guard)? {
+ if let Some(content) = try_apply(vt, &target, recipe, guard)? {
realized = Some(content);
break;
}
@@ -46,7 +43,7 @@ pub fn realize(
if let Some(showable) = target.with::<dyn Show>() {
let guard = Guard::Base(target.id());
if realized.is_none() && !target.is_guarded(guard) {
- realized = Some(showable.show(world, styles));
+ realized = Some(showable.show(vt, target, styles));
}
}
@@ -64,7 +61,7 @@ pub fn realize(
/// Try to apply a recipe to the target.
fn try_apply(
- world: Tracked<dyn World>,
+ vt: &Vt,
target: &Content,
recipe: &Recipe,
guard: Guard,
@@ -75,7 +72,7 @@ fn try_apply(
return Ok(None);
}
- recipe.apply(world, target.clone().guarded(guard)).map(Some)
+ recipe.apply(vt.world(), target.clone().guarded(guard)).map(Some)
}
Some(Selector::Label(label)) => {
@@ -83,7 +80,7 @@ fn try_apply(
return Ok(None);
}
- recipe.apply(world, target.clone().guarded(guard)).map(Some)
+ recipe.apply(vt.world(), target.clone().guarded(guard)).map(Some)
}
Some(Selector::Regex(regex)) => {
@@ -107,7 +104,7 @@ fn try_apply(
}
let piece = make(m.as_str().into()).guarded(guard);
- let transformed = recipe.apply(world, piece)?;
+ let transformed = recipe.apply(vt.world(), piece)?;
result.push(transformed);
cursor = m.end();
}
@@ -131,7 +128,7 @@ fn try_apply(
#[capability]
pub trait Show {
/// Execute the base recipe for this node.
- fn show(&self, world: Tracked<dyn World>, styles: StyleChain) -> Content;
+ fn show(&self, vt: &mut Vt, this: &Content, styles: StyleChain) -> Content;
}
/// Post-process a node after it was realized.