summaryrefslogtreecommitdiff
path: root/src/library/spacing.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/library/spacing.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/library/spacing.rs')
-rw-r--r--src/library/spacing.rs46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/library/spacing.rs b/src/library/spacing.rs
index 81112cbd..3cd775c9 100644
--- a/src/library/spacing.rs
+++ b/src/library/spacing.rs
@@ -6,44 +6,32 @@ use super::*;
///
/// # Positional arguments
/// - The spacing (length or relative to font size).
-pub fn h(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> {
- spacing(call, Horizontal)
+pub async fn h(args: TableValue, ctx: LayoutContext<'_>) -> Pass<Value> {
+ spacing(args, ctx, Horizontal).await
}
/// `v`: Add vertical spacing.
///
/// # Positional arguments
/// - The spacing (length or relative to font size).
-pub fn v(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> {
- spacing(call, Vertical)
+pub async fn v(args: TableValue, ctx: LayoutContext<'_>) -> Pass<Value> {
+ spacing(args, ctx, Vertical).await
}
-fn spacing(call: FuncCall, axis: SpecAxis) -> Pass<SyntaxNode> {
+async fn spacing(
+ mut args: TableValue,
+ ctx: LayoutContext<'_>,
+ axis: SpecAxis,
+) -> Pass<Value> {
let mut f = Feedback::new();
- let mut args = call.args;
- let node = SpacingNode {
- spacing: args.expect::<ScaleLength>(&mut f)
- .map(|s| (axis, s))
- .or_missing(call.name.span, "spacing", &mut f),
- };
+ let spacing = args.expect::<ScaleLength>(&mut f).map(|s| (axis, s));
args.unexpected(&mut f);
- Pass::node(node, f)
-}
-
-#[derive(Debug, Clone, PartialEq)]
-struct SpacingNode {
- spacing: Option<(SpecAxis, ScaleLength)>,
-}
-#[async_trait(?Send)]
-impl Layout for SpacingNode {
- async fn layout<'a>(&'a self, ctx: LayoutContext<'_>) -> Pass<Commands<'a>> {
- Pass::okay(if let Some((axis, spacing)) = self.spacing {
- let axis = axis.to_generic(ctx.axes);
- let spacing = spacing.raw_scaled(ctx.style.text.font_size());
- vec![AddSpacing(spacing, SpacingKind::Hard, axis)]
- } else {
- vec![]
- })
- }
+ Pass::commands(if let Some((axis, spacing)) = spacing {
+ let axis = axis.to_generic(ctx.axes);
+ let spacing = spacing.raw_scaled(ctx.style.text.font_size());
+ vec![AddSpacing(spacing, SpacingKind::Hard, axis)]
+ } else {
+ vec![]
+ }, f)
}