diff --git a/macros/src/lib.rs b/macros/src/lib.rs index dbea1f831..8614a26ff 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -100,7 +100,7 @@ fn expand(stream: TokenStream2, mut impl_block: syn::ItemImpl) -> Result::Output as eval::Fold>::Output) + parse_quote!(<<#value_ty as model::Resolve>::Output as model::Fold>::Output) } else if property.fold { - parse_quote!(<#value_ty as eval::Fold>::Output) + parse_quote!(<#value_ty as model::Fold>::Output) } else if property.resolve { - parse_quote!(<#value_ty as eval::Resolve>::Output) + parse_quote!(<#value_ty as model::Resolve>::Output) } else { value_ty.clone() }; @@ -195,8 +195,8 @@ fn process_const( } else if property.resolve && property.fold { get = quote! { match values.next().cloned() { - Some(value) => eval::Fold::fold( - eval::Resolve::resolve(value, chain), + Some(value) => model::Fold::fold( + model::Resolve::resolve(value, chain), Self::get(chain, values), ), None => #default, @@ -205,12 +205,12 @@ fn process_const( } else if property.resolve { get = quote! { let value = values.next().cloned().unwrap_or(#default); - eval::Resolve::resolve(value, chain) + model::Resolve::resolve(value, chain) }; } else if property.fold { get = quote! { match values.next().cloned() { - Some(value) => eval::Fold::fold(value, Self::get(chain, values)), + Some(value) => model::Fold::fold(value, Self::get(chain, values)), None => #default, } }; @@ -243,7 +243,7 @@ fn process_const( } } - impl<'a, #params> eval::Key<'a> for #key { + impl<'a, #params> model::Key<'a> for #key { type Value = #value_ty; type Output = #output_ty; diff --git a/src/eval/func.rs b/src/eval/func.rs index fcd19326f..b2ecfe939 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -2,8 +2,9 @@ use std::fmt::{self, Debug, Formatter, Write}; use std::hash::{Hash, Hasher}; use std::sync::Arc; -use super::{Args, Content, Control, Eval, Scope, Scopes, StyleMap, Value}; +use super::{Args, Control, Eval, Scope, Scopes, Value}; use crate::diag::{StrResult, TypResult}; +use crate::model::{Content, StyleMap}; use crate::syntax::ast::Expr; use crate::syntax::Span; use crate::util::EcoString; diff --git a/src/eval/mod.rs b/src/eval/mod.rs index f77efe47a..2839baff6 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -6,38 +6,28 @@ mod array; mod dict; #[macro_use] mod value; -#[macro_use] -mod styles; + mod args; mod capture; -mod collapse; -mod content; mod control; mod func; -mod layout; pub mod methods; mod module; pub mod ops; mod raw; mod scope; -mod show; mod str; pub use self::str::*; pub use args::*; pub use array::*; pub use capture::*; -pub use collapse::*; -pub use content::*; pub use control::*; pub use dict::*; pub use func::*; -pub use layout::*; pub use module::*; pub use raw::*; pub use scope::*; -pub use show::*; -pub use styles::*; pub use value::*; use std::collections::BTreeMap; @@ -48,6 +38,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::diag::{At, StrResult, Trace, Tracepoint, TypResult}; use crate::geom::{Angle, Em, Fraction, Length, Ratio}; use crate::library; +use crate::model::{Content, StyleMap}; use crate::syntax::ast::*; use crate::syntax::{Span, Spanned}; use crate::util::EcoString; diff --git a/src/eval/module.rs b/src/eval/module.rs index 4460caece..d2b4c520f 100644 --- a/src/eval/module.rs +++ b/src/eval/module.rs @@ -1,4 +1,5 @@ -use super::{Content, Scope}; +use super::Scope; +use crate::model::Content; use crate::source::{SourceId, SourceStore}; /// An evaluated module, ready for importing or layouting. diff --git a/src/eval/ops.rs b/src/eval/ops.rs index 703520395..832bd354b 100644 --- a/src/eval/ops.rs +++ b/src/eval/ops.rs @@ -5,6 +5,7 @@ use std::cmp::Ordering; use super::{Dynamic, RawAlign, RawStroke, Smart, StrExt, Value}; use crate::diag::StrResult; use crate::geom::{Numeric, Spec, SpecAxis}; +use crate::model; use Value::*; /// Bail with a type mismatch error. @@ -20,8 +21,8 @@ pub fn join(lhs: Value, rhs: Value) -> StrResult { (a, None) => a, (None, b) => b, (Str(a), Str(b)) => Str(a + b), - (Str(a), Content(b)) => Content(super::Content::Text(a) + b), - (Content(a), Str(b)) => Content(a + super::Content::Text(b)), + (Str(a), Content(b)) => Content(model::Content::Text(a) + b), + (Content(a), Str(b)) => Content(a + model::Content::Text(b)), (Content(a), Content(b)) => Content(a + b), (Array(a), Array(b)) => Array(a + b), (Dict(a), Dict(b)) => Dict(a + b), @@ -86,8 +87,8 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult { (Content(a), None) => Content(a), (None, Content(b)) => Content(b), (Content(a), Content(b)) => Content(a + b), - (Content(a), Str(b)) => Content(a + super::Content::Text(b)), - (Str(a), Content(b)) => Content(super::Content::Text(a) + b), + (Content(a), Str(b)) => Content(a + model::Content::Text(b)), + (Str(a), Content(b)) => Content(model::Content::Text(a) + b), (Array(a), Array(b)) => Array(a + b), (Dict(a), Dict(b)) => Dict(a + b), diff --git a/src/eval/raw.rs b/src/eval/raw.rs index 6792c4915..2d82fca8d 100644 --- a/src/eval/raw.rs +++ b/src/eval/raw.rs @@ -2,11 +2,12 @@ use std::cmp::Ordering; use std::fmt::{self, Debug, Formatter}; use std::ops::{Add, Div, Mul, Neg}; -use super::{Fold, Resolve, Smart, StyleChain, Value}; +use super::{Smart, Value}; use crate::geom::{ Align, Em, Get, Length, Numeric, Paint, Relative, Spec, SpecAxis, Stroke, }; use crate::library::text::TextNode; +use crate::model::{Fold, Resolve, StyleChain}; /// The unresolved alignment representation. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] diff --git a/src/eval/value.rs b/src/eval/value.rs index 2ef260590..31287fa86 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -5,12 +5,13 @@ use std::hash::{Hash, Hasher}; use std::num::NonZeroUsize; use std::sync::Arc; -use super::{ops, Args, Array, Content, Dict, Func, Layout, LayoutNode, RawLength}; +use super::{ops, Args, Array, Dict, Func, RawLength}; use crate::diag::{with_alternative, StrResult}; use crate::geom::{ Angle, Color, Dir, Em, Fraction, Length, Paint, Ratio, Relative, RgbaColor, }; use crate::library::text::RawNode; +use crate::model::{Content, Layout, LayoutNode}; use crate::syntax::Spanned; use crate::util::EcoString; diff --git a/src/lib.rs b/src/lib.rs index 6dc52b67c..0edaeb99c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,8 @@ //! provided in the [AST] module. //! - **Evaluation:** The next step is to [evaluate] the markup. This produces a //! [module], consisting of a scope of values that were exported by the code -//! and [content], a hierarchical, styled representation with the contents -//! of the module. The nodes of this tree are well structured and +//! and [content], a hierarchical, styled representation with the contents of +//! the module. The nodes of the content tree are well structured and //! order-independent and thus much better suited for layouting than the raw //! markup. //! - **Layouting:** Next, the tree is [layouted] into a portable version of the @@ -23,8 +23,8 @@ //! [AST]: syntax::ast //! [evaluate]: eval::Eval //! [module]: eval::Module -//! [content]: eval::Content -//! [layouted]: eval::Content::layout +//! [content]: model::Content +//! [layouted]: model::Content::layout //! [PDF]: export::pdf #![allow(clippy::len_without_is_empty)] @@ -45,6 +45,7 @@ pub mod frame; pub mod image; pub mod library; pub mod loading; +pub mod model; pub mod parse; pub mod source; pub mod syntax; @@ -57,11 +58,12 @@ use std::path::PathBuf; use std::sync::Arc; use crate::diag::TypResult; -use crate::eval::{Eval, Module, Scope, Scopes, StyleMap}; +use crate::eval::{Eval, Module, Scope, Scopes}; use crate::font::FontStore; use crate::frame::Frame; use crate::image::ImageStore; use crate::loading::Loader; +use crate::model::StyleMap; use crate::source::{SourceId, SourceStore}; /// The core context which holds the loader, configuration and cached artifacts. diff --git a/src/library/prelude.rs b/src/library/prelude.rs index a79f3c607..584b2ab20 100644 --- a/src/library/prelude.rs +++ b/src/library/prelude.rs @@ -9,12 +9,15 @@ pub use typst_macros::node; pub use crate::diag::{with_alternative, At, Error, StrResult, TypError, TypResult}; pub use crate::eval::{ - Arg, Args, Array, Cast, Content, Dict, Fold, Func, Key, Layout, LayoutNode, Node, - RawAlign, RawLength, RawStroke, Regions, Resolve, Scope, Show, ShowNode, Smart, - StyleChain, StyleMap, StyleVec, Value, + Arg, Args, Array, Cast, Dict, Func, Node, RawAlign, RawLength, RawStroke, Scope, + Smart, Value, }; pub use crate::frame::*; pub use crate::geom::*; +pub use crate::model::{ + Content, Fold, Key, Layout, LayoutNode, Regions, Resolve, Show, ShowNode, StyleChain, + StyleMap, StyleVec, +}; pub use crate::syntax::{Span, Spanned}; pub use crate::util::{EcoString, OptionExt}; pub use crate::Context; diff --git a/src/eval/collapse.rs b/src/model/collapse.rs similarity index 100% rename from src/eval/collapse.rs rename to src/model/collapse.rs diff --git a/src/eval/content.rs b/src/model/content.rs similarity index 100% rename from src/eval/content.rs rename to src/model/content.rs diff --git a/src/eval/layout.rs b/src/model/layout.rs similarity index 99% rename from src/eval/layout.rs rename to src/model/layout.rs index 117c269a7..da6290ae5 100644 --- a/src/eval/layout.rs +++ b/src/model/layout.rs @@ -5,8 +5,9 @@ use std::fmt::{self, Debug, Formatter}; use std::hash::Hash; use std::sync::Arc; -use super::{Barrier, RawAlign, RawLength, Resolve, StyleChain}; +use super::{Barrier, Resolve, StyleChain}; use crate::diag::TypResult; +use crate::eval::{RawAlign, RawLength}; use crate::frame::{Element, Frame, Geometry}; use crate::geom::{Align, Length, Paint, Point, Relative, Sides, Size, Spec, Stroke}; use crate::library::graphics::MoveNode; diff --git a/src/model/mod.rs b/src/model/mod.rs new file mode 100644 index 000000000..df39207ff --- /dev/null +++ b/src/model/mod.rs @@ -0,0 +1,14 @@ +//! Structured representation of styled content. + +#[macro_use] +mod styles; +mod collapse; +mod content; +mod layout; +mod show; + +pub use collapse::*; +pub use content::*; +pub use layout::*; +pub use show::*; +pub use styles::*; diff --git a/src/eval/show.rs b/src/model/show.rs similarity index 97% rename from src/eval/show.rs rename to src/model/show.rs index c374c2df2..5f76ba191 100644 --- a/src/eval/show.rs +++ b/src/model/show.rs @@ -3,8 +3,9 @@ use std::fmt::{self, Debug, Formatter}; use std::hash::Hash; use std::sync::Arc; -use super::{Content, Dict, StyleChain}; +use super::{Content, StyleChain}; use crate::diag::TypResult; +use crate::eval::Dict; use crate::util::Prehashed; use crate::Context; diff --git a/src/eval/styles.rs b/src/model/styles.rs similarity index 99% rename from src/eval/styles.rs rename to src/model/styles.rs index b666c85dd..2195568d6 100644 --- a/src/eval/styles.rs +++ b/src/model/styles.rs @@ -4,11 +4,13 @@ use std::hash::Hash; use std::marker::PhantomData; use std::sync::Arc; -use super::{Args, Content, Func, Layout, Node, Show, ShowNode, Smart, Span, Value}; +use super::{Content, Layout, Show, ShowNode}; use crate::diag::{At, TypResult}; +use crate::eval::{Args, Func, Node, Smart, Value}; use crate::geom::{Numeric, Relative, Sides, Spec}; use crate::library::layout::PageNode; use crate::library::text::{FontFamily, ParNode, TextNode}; +use crate::syntax::Span; use crate::util::Prehashed; use crate::Context; diff --git a/tests/typeset.rs b/tests/typeset.rs index 531674f34..9f84a733a 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -10,12 +10,13 @@ use unscanny::Scanner; use walkdir::WalkDir; use typst::diag::Error; -use typst::eval::{Smart, StyleMap, Value}; +use typst::eval::{Smart, Value}; use typst::frame::{Element, Frame}; use typst::geom::{Length, RgbaColor}; use typst::library::layout::PageNode; use typst::library::text::{TextNode, TextSize}; use typst::loading::FsLoader; +use typst::model::StyleMap; use typst::source::SourceFile; use typst::syntax::Span; use typst::{bail, Context};