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/func.rs | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/func.rs (limited to 'src/func.rs') diff --git a/src/func.rs b/src/func.rs deleted file mode 100644 index bff4fdab..00000000 --- a/src/func.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! Tools for building custom functions. - -/// Useful things for creating functions. -pub mod prelude { - pub use async_trait::async_trait; - pub use crate::layout::prelude::*; - pub use crate::layout::Commands; - pub use crate::layout::Command::{self, *}; - pub use crate::style::*; - pub use crate::syntax::expr::*; - pub use crate::syntax::parsing::{parse, FuncCall, ParseState}; - pub use crate::syntax::span::{Pos, Span, SpanVec, Spanned}; - pub use crate::syntax::tree::{DynamicNode, SyntaxNode, SyntaxTree}; - pub use crate::{Pass, Feedback}; - pub use super::*; -} - -use prelude::*; - -/// Extra methods on `Option`s used for function argument parsing. -pub trait OptionExt: Sized { - /// Call `f` with `val` if this is `Some(val)`. - fn with(self, f: impl FnOnce(T)); - - /// Report an error about a missing argument with the given name and span if - /// the option is `None`. - fn or_missing(self, span: Span, arg: &str, f: &mut Feedback) -> Self; -} - -impl OptionExt for Option { - fn with(self, f: impl FnOnce(T)) { - if let Some(val) = self { - f(val); - } - } - - fn or_missing(self, span: Span, arg: &str, f: &mut Feedback) -> Self { - if self.is_none() { - error!(@f, span, "missing argument: {}", arg); - } - self - } -} -- cgit v1.2.3