diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-04 13:48:07 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-04 13:48:07 +0200 |
| commit | 2467cd6272c13b618ad53c5dadff5b8c8e7885bf (patch) | |
| tree | 6ad13ec06a04997564efc514b40daa3fb65233e2 /src/lib.rs | |
| parent | ed4fdcb0ada909f1cc3d7436334e253f0ec14d55 (diff) | |
Refactor function parsing ♻
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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 { |
