From 30f16bbf6431ca0c174ca0a1abaa6a13ef50ab06 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 16 Aug 2020 22:14:27 +0200 Subject: =?UTF-8?q?Add=20Value=20type=20and=20replace=20dyn-nodes=20with?= =?UTF-8?q?=20call-exprs=20=F0=9F=8F=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/lib.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/lib.rs') 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 { - 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 Pass { } } -impl Pass { - /// Create a new pass from an unboxed dynamic node and feedback data.. - pub fn node(node: T, feedback: Feedback) -> Self { - Pass::new(SyntaxNode::boxed(node), feedback) +impl Pass { + /// Create a new pass with a list of layouting commands. + pub fn commands(commands: Commands, feedback: Feedback) -> Self { + Pass::new(Value::Commands(commands), feedback) } } -- cgit v1.2.3