From 53ca5a7fc5829d4c5b1cffc6d5a5f1706f8ec3cd Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 27 Jul 2020 13:47:29 +0200 Subject: =?UTF-8?q?Refactor=20parser=20=F0=9F=9A=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index b140f47d..7f175279 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ use toddle::query::{FontProvider, FontIndex, FontDescriptor}; use crate::problem::Problems; use crate::layout::MultiLayout; use crate::style::{LayoutStyle, PageStyle, TextStyle}; -use crate::syntax::{SyntaxModel, Scope, Decoration, ParseContext, parse}; +use crate::syntax::{SyntaxModel, Scope, Decoration, ParseState, parse}; use crate::syntax::span::{Position, SpanVec, offset_spans}; @@ -42,6 +42,8 @@ macro_rules! pub_use_mod { }; } +#[macro_use] +mod macros; #[macro_use] pub mod problem; pub mod export; @@ -57,14 +59,13 @@ pub mod syntax; /// Transforms source code into typesetted layouts. /// /// A typesetter can be configured through various methods. -#[derive(Debug)] pub struct Typesetter { /// The font loader shared by all typesetting processes. loader: GlobalFontLoader, /// The base layouting style. style: LayoutStyle, - /// The standard library scope. - scope: Scope, + /// The base parser state. + parse_state: ParseState, /// Whether to render debug boxes. debug: bool, } @@ -84,7 +85,7 @@ impl Typesetter { Typesetter { loader: RefCell::new(FontLoader::new(provider)), style: LayoutStyle::default(), - scope: Scope::with_std(), + parse_state: ParseState { scope: Scope::with_std() }, debug: false, } } @@ -111,7 +112,7 @@ impl Typesetter { /// Parse source code into a syntax tree. pub fn parse(&self, src: &str) -> Pass { - parse(Position::ZERO, src, ParseContext { scope: &self.scope }) + parse(src, Position::ZERO, &self.parse_state) } /// Layout a syntax tree and return the produced layout. @@ -204,9 +205,9 @@ impl Feedback { /// Add more feedback whose spans are local and need to be offset by an /// `offset` to be correct for this feedbacks context. - pub fn extend_offset(&mut self, offset: Position, other: Feedback) { - self.problems.extend(offset_spans(offset, other.problems)); - self.decos.extend(offset_spans(offset, other.decos)); + pub fn extend_offset(&mut self, other: Feedback, offset: Position) { + self.problems.extend(offset_spans(other.problems, offset)); + self.decos.extend(offset_spans(other.decos, offset)); } } -- cgit v1.2.3 From 9672d4320052d08b67d497febed4a0ad78bf9252 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 29 Jul 2020 17:38:14 +0200 Subject: =?UTF-8?q?Improve=20argument=20naming=20and=20fix=20grammar=20in?= =?UTF-8?q?=20comment=20=E2=99=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 7f175279..8f5bbdd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,10 +204,10 @@ impl Feedback { } /// Add more feedback whose spans are local and need to be offset by an - /// `offset` to be correct for this feedbacks context. - pub fn extend_offset(&mut self, other: Feedback, offset: Position) { - self.problems.extend(offset_spans(other.problems, offset)); - self.decos.extend(offset_spans(other.decos, offset)); + /// `offset` to be correct in this feedback's context. + pub fn extend_offset(&mut self, more: Feedback, offset: Position) { + self.problems.extend(offset_spans(more.problems, offset)); + self.decos.extend(offset_spans(more.decos, offset)); } } -- cgit v1.2.3