Extract model module

This commit is contained in:
Laurenz 2022-04-24 15:42:56 +02:00
parent e4ee14e54f
commit 8fbb11fc05
16 changed files with 60 additions and 40 deletions

View File

@ -100,7 +100,7 @@ fn expand(stream: TokenStream2, mut impl_block: syn::ItemImpl) -> Result<TokenSt
use std::any::TypeId;
use std::marker::PhantomData;
use once_cell::sync::Lazy;
use crate::eval;
use crate::{eval, model};
use super::*;
#impl_block
@ -156,11 +156,11 @@ fn process_const(
let output_ty = if property.referenced {
parse_quote!(&'a #value_ty)
} else if property.fold && property.resolve {
parse_quote!(<<#value_ty as eval::Resolve>::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;

View File

@ -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;

View File

@ -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;

View File

@ -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.

View File

@ -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<Value> {
(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<Value> {
(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),

View File

@ -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)]

View File

@ -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;

View File

@ -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.

View File

@ -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;

View File

@ -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;

14
src/model/mod.rs Normal file
View File

@ -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::*;

View File

@ -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;

View File

@ -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;

View File

@ -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};