summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-04 13:48:07 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-04 13:48:07 +0200
commit2467cd6272c13b618ad53c5dadff5b8c8e7885bf (patch)
tree6ad13ec06a04997564efc514b40daa3fb65233e2 /src/lib.rs
parented4fdcb0ada909f1cc3d7436334e253f0ec14d55 (diff)
Refactor function parsing ♻
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fa6300bb..38109a15 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -48,7 +48,7 @@ use crate::style::{LayoutStyle, PageStyle, TextStyle};
use crate::syntax::decoration::Decorations;
use crate::syntax::parsing::{parse, ParseState};
use crate::syntax::span::{Offset, Pos};
-use crate::syntax::tree::SyntaxTree;
+use crate::syntax::tree::{DynamicNode, SyntaxNode, SyntaxTree};
/// Transforms source code into typesetted layouts.
///
@@ -68,7 +68,7 @@ impl Typesetter {
Self {
loader,
style: LayoutStyle::default(),
- parse_state: ParseState { scope: crate::library::std() },
+ parse_state: ParseState { scope: crate::library::_std() },
}
}
@@ -90,7 +90,6 @@ impl Typesetter {
/// Layout a syntax tree and return the produced layout.
pub async fn layout(&self, tree: &SyntaxTree) -> Pass<MultiLayout> {
use crate::layout::prelude::*;
- use crate::layout::{LayoutContext, LayoutSpace};
let margins = self.style.page.margins();
layout(
@@ -141,6 +140,11 @@ impl<T> Pass<T> {
Self { output, feedback }
}
+ /// Create a new pass with empty feedback.
+ pub fn okay(output: T) -> Self {
+ Self { output, feedback: Feedback::new() }
+ }
+
/// Map the output type and keep the feedback data.
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Pass<U> {
Pass {
@@ -150,6 +154,13 @@ 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)
+ }
+}
+
/// Diagnostic and semantic syntax highlighting data.
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Feedback {