diff options
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/content.rs | 8 | ||||
| -rw-r--r-- | src/model/eval.rs | 8 | ||||
| -rw-r--r-- | src/model/realize.rs | 2 | ||||
| -rw-r--r-- | src/model/recipe.rs | 9 | ||||
| -rw-r--r-- | src/model/show.rs | 10 | ||||
| -rw-r--r-- | src/model/styles.rs | 4 |
6 files changed, 17 insertions, 24 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index 530862a2..3cdc6341 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use comemo::Tracked; use super::{ - Builder, Dict, Key, Layout, LayoutNode, Property, Regions, Scratch, Selector, Show, + Builder, Key, Layout, LayoutNode, Property, Regions, Scratch, Selector, Show, ShowNode, StyleChain, StyleEntry, StyleMap, }; use crate::diag::{SourceResult, StrResult}; @@ -73,7 +73,7 @@ pub enum Content { Page(PageNode), /// A node that can be realized with styles, optionally with attached /// properties. - Show(ShowNode, Option<Dict>), + Show(ShowNode), /// Content with attached styles. Styled(Arc<(Self, StyleMap)>), /// A sequence of multiple nodes. @@ -107,7 +107,7 @@ impl Content { where T: Show + Debug + Hash + Sync + Send + 'static, { - Self::Show(node.pack(), None) + Self::Show(node.pack()) } /// Create a new sequence node from multiples nodes. @@ -242,7 +242,7 @@ impl Debug for Content { Self::Item(item) => item.fmt(f), Self::Pagebreak { weak } => write!(f, "Pagebreak({weak})"), Self::Page(page) => page.fmt(f), - Self::Show(node, _) => node.fmt(f), + Self::Show(node) => node.fmt(f), Self::Styled(styled) => { let (sub, map) = styled.as_ref(); map.fmt(f)?; diff --git a/src/model/eval.rs b/src/model/eval.rs index 9051c955..ca1c7974 100644 --- a/src/model/eval.rs +++ b/src/model/eval.rs @@ -8,7 +8,7 @@ use unicode_segmentation::UnicodeSegmentation; use super::{ methods, ops, Arg, Args, Array, CapturesVisitor, Closure, Content, Dict, Flow, Func, - Pattern, Recipe, Scope, Scopes, StyleEntry, StyleMap, Value, Vm, + Pattern, Recipe, Scope, Scopes, Show, StyleEntry, StyleMap, Value, Vm, }; use crate::diag::{At, SourceResult, StrResult, Trace, Tracepoint}; use crate::geom::{Abs, Angle, Em, Fr, Ratio}; @@ -706,9 +706,9 @@ impl Eval for ast::FieldAccess { Ok(match object { Value::Dict(dict) => dict.get(&field).at(span)?.clone(), - Value::Content(Content::Show(_, Some(dict))) => dict - .get(&field) - .map_err(|_| format!("unknown field {field:?}")) + Value::Content(Content::Show(node)) => node + .field(&field) + .ok_or_else(|| format!("unknown field {field:?}")) .at(span)? .clone(), diff --git a/src/model/realize.rs b/src/model/realize.rs index 895c4f33..69bae91f 100644 --- a/src/model/realize.rs +++ b/src/model/realize.rs @@ -87,7 +87,7 @@ impl<'a> Builder<'a> { } } - Content::Show(node, _) => return self.show(node, styles), + Content::Show(node) => return self.show(node, styles), Content::Styled(styled) => return self.styled(styled, styles), Content::Sequence(seq) => return self.sequence(seq, styles), diff --git a/src/model/recipe.rs b/src/model/recipe.rs index 46dad6d1..8124d441 100644 --- a/src/model/recipe.rs +++ b/src/model/recipe.rs @@ -3,8 +3,7 @@ use std::fmt::{self, Debug, Formatter}; use comemo::Tracked; use super::{ - Args, Content, Func, Interruption, NodeId, Regex, Show, ShowNode, StyleChain, - StyleEntry, Value, + Args, Content, Func, Interruption, NodeId, Regex, Show, ShowNode, StyleEntry, Value, }; use crate::diag::SourceResult; use crate::library::structure::{DescNode, EnumNode, ListNode}; @@ -34,17 +33,13 @@ impl Recipe { pub fn apply( &self, world: Tracked<dyn World>, - styles: StyleChain, sel: Selector, target: Target, ) -> SourceResult<Option<Content>> { let content = match (target, &self.pattern) { (Target::Node(node), &Pattern::Node(id)) if node.id() == id => { let node = node.unguard(sel); - self.call(world, || { - let dict = node.encode(styles); - Value::Content(Content::Show(node, Some(dict))) - })? + self.call(world, || Value::Content(Content::Show(node)))? } (Target::Text(text), Pattern::Regex(regex)) => { diff --git a/src/model/show.rs b/src/model/show.rs index bff69448..86659463 100644 --- a/src/model/show.rs +++ b/src/model/show.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use comemo::{Prehashed, Tracked}; -use super::{Content, Dict, NodeId, Selector, StyleChain}; +use super::{Content, NodeId, Selector, StyleChain, Value}; use crate::diag::SourceResult; use crate::World; @@ -13,8 +13,8 @@ pub trait Show: 'static { /// Unguard nested content against recursive show rules. fn unguard(&self, sel: Selector) -> ShowNode; - /// Encode this node into a dictionary. - fn encode(&self, styles: StyleChain) -> Dict; + /// Access a field on this node. + fn field(&self, name: &str) -> Option<Value>; /// The base recipe for this node that is executed if there is no /// user-defined show rule. @@ -74,8 +74,8 @@ impl Show for ShowNode { self.0.unguard(sel) } - fn encode(&self, styles: StyleChain) -> Dict { - self.0.encode(styles) + fn field(&self, name: &str) -> Option<Value> { + self.0.field(name) } fn realize( diff --git a/src/model/styles.rs b/src/model/styles.rs index ddeeaa53..f3bd8c4f 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -286,9 +286,7 @@ impl<'a> StyleChain<'a> { let sel = Selector::Nth(n); if self.guarded(sel) { guarded = true; - } else if let Some(content) = - recipe.apply(world, self, sel, target)? - { + } else if let Some(content) = recipe.apply(world, sel, target)? { realized = Some(content); break; } |
