summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-16 22:14:27 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-16 22:39:21 +0200
commit30f16bbf6431ca0c174ca0a1abaa6a13ef50ab06 (patch)
treef5a5c0adad15840ebe24b39e77ff467862067c91 /src/lib.rs
parent9f6137d8a829fe8f34554623495fa620252a0184 (diff)
Add Value type and replace dyn-nodes with call-exprs 🏗
- In addition to syntax trees there are now `Value`s, which syntax trees can be evaluated into (e.g. the tree is `5+5` and the value is `10`) - Parsing is completely pure, function calls are not parsed into nodes, but into simple call expressions, which are resolved later - Functions aren't dynamic nodes anymore, but simply functions which receive their arguments as a table and the layouting context - Functions may return any `Value` - Layouting is powered by functions which return the new `Commands` value, which informs the layouting engine what to do - When a function returns a non-`Commands` value, the layouter simply dumps the value into the document in monospace
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 21adad9e..e30e41b2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -24,9 +24,9 @@
mod macros;
#[macro_use]
pub mod diagnostic;
-#[macro_use]
-pub mod func;
+pub mod color;
+pub mod compute;
pub mod export;
pub mod font;
pub mod geom;
@@ -34,22 +34,24 @@ pub mod layout;
pub mod length;
pub mod library;
pub mod paper;
+pub mod prelude;
pub mod style;
pub mod syntax;
-pub mod table;
use std::fmt::Debug;
use std::future::Future;
use std::pin::Pin;
+use crate::compute::scope::Scope;
+use crate::compute::value::Value;
use crate::diagnostic::Diagnostics;
use crate::font::SharedFontLoader;
-use crate::layout::MultiLayout;
+use crate::layout::{Commands, MultiLayout};
use crate::style::{LayoutStyle, PageStyle, TextStyle};
use crate::syntax::decoration::Decorations;
-use crate::syntax::parsing::{parse, ParseState};
+use crate::syntax::parsing::parse;
use crate::syntax::span::{Offset, Pos};
-use crate::syntax::tree::{DynamicNode, SyntaxNode, SyntaxTree};
+use crate::syntax::tree::SyntaxTree;
/// Transforms source code into typesetted layouts.
///
@@ -57,10 +59,10 @@ use crate::syntax::tree::{DynamicNode, SyntaxNode, SyntaxTree};
pub struct Typesetter {
/// The font loader shared by all typesetting processes.
loader: SharedFontLoader,
+ /// A scope that contains the standard library function definitions.
+ std: Scope,
/// The base layouting style.
style: LayoutStyle,
- /// The base parser state.
- parse_state: ParseState,
}
impl Typesetter {
@@ -68,8 +70,8 @@ impl Typesetter {
pub fn new(loader: SharedFontLoader) -> Self {
Self {
loader,
+ std: crate::library::_std(),
style: LayoutStyle::default(),
- parse_state: ParseState { scope: crate::library::_std() },
}
}
@@ -85,7 +87,7 @@ impl Typesetter {
/// Parse source code into a syntax tree.
pub fn parse(&self, src: &str) -> Pass<SyntaxTree> {
- parse(src, Pos::ZERO, &self.parse_state)
+ parse(src, Pos::ZERO)
}
/// Layout a syntax tree and return the produced layout.
@@ -97,6 +99,7 @@ impl Typesetter {
&tree,
LayoutContext {
loader: &self.loader,
+ scope: &self.std,
style: &self.style,
base: self.style.page.size.unpadded(margins),
spaces: vec![LayoutSpace {
@@ -155,10 +158,10 @@ impl<T> Pass<T> {
}
}
-impl Pass<SyntaxNode> {
- /// Create a new pass from an unboxed dynamic node and feedback data..
- pub fn node<T: DynamicNode + 'static>(node: T, feedback: Feedback) -> Self {
- Pass::new(SyntaxNode::boxed(node), feedback)
+impl Pass<Value> {
+ /// Create a new pass with a list of layouting commands.
+ pub fn commands(commands: Commands, feedback: Feedback) -> Self {
+ Pass::new(Value::Commands(commands), feedback)
}
}