summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-24 15:42:56 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-24 15:47:42 +0200
commit8fbb11fc05b3313bf102c1f23693290661d00863 (patch)
treea198db77338f1cc1304fe50f55020b08e22bca60 /src
parente4ee14e54fb87961096856c7ea105435b7cc3c45 (diff)
Extract `model` module
Diffstat (limited to 'src')
-rw-r--r--src/eval/func.rs3
-rw-r--r--src/eval/mod.rs13
-rw-r--r--src/eval/module.rs3
-rw-r--r--src/eval/ops.rs9
-rw-r--r--src/eval/raw.rs3
-rw-r--r--src/eval/value.rs3
-rw-r--r--src/lib.rs12
-rw-r--r--src/library/prelude.rs9
-rw-r--r--src/model/collapse.rs (renamed from src/eval/collapse.rs)0
-rw-r--r--src/model/content.rs (renamed from src/eval/content.rs)0
-rw-r--r--src/model/layout.rs (renamed from src/eval/layout.rs)3
-rw-r--r--src/model/mod.rs14
-rw-r--r--src/model/show.rs (renamed from src/eval/show.rs)3
-rw-r--r--src/model/styles.rs (renamed from src/eval/styles.rs)4
14 files changed, 49 insertions, 30 deletions
diff --git a/src/eval/func.rs b/src/eval/func.rs
index fcd19326..b2ecfe93 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 f77efe47..2839baff 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 4460caec..d2b4c520 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 70352039..832bd354 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<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),
diff --git a/src/eval/raw.rs b/src/eval/raw.rs
index 6792c491..2d82fca8 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 2ef26059..31287fa8 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 6dc52b67..0edaeb99 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 a79f3c60..584b2ab2 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
index 5e7a25f8..5e7a25f8 100644
--- a/src/eval/collapse.rs
+++ b/src/model/collapse.rs
diff --git a/src/eval/content.rs b/src/model/content.rs
index 2465f0e3..2465f0e3 100644
--- a/src/eval/content.rs
+++ b/src/model/content.rs
diff --git a/src/eval/layout.rs b/src/model/layout.rs
index 117c269a..da6290ae 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 00000000..df39207f
--- /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
index c374c2df..5f76ba19 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
index b666c85d..2195568d 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;