From 2467cd6272c13b618ad53c5dadff5b8c8e7885bf Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 4 Aug 2020 13:48:07 +0200 Subject: =?UTF-8?q?Refactor=20function=20parsing=20=E2=99=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') 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 { use crate::layout::prelude::*; - use crate::layout::{LayoutContext, LayoutSpace}; let margins = self.style.page.margins(); layout( @@ -141,6 +140,11 @@ impl Pass { 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(self, f: impl FnOnce(T) -> U) -> Pass { Pass { @@ -150,6 +154,13 @@ 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) + } +} + /// Diagnostic and semantic syntax highlighting data. #[derive(Debug, Default, Clone, Eq, PartialEq)] pub struct Feedback { -- cgit v1.2.3