From e089b6ea40015e012302dc55ac5d6cb42ca4876e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 8 Feb 2022 16:39:37 +0100 Subject: Set rules for everything --- src/eval/mod.rs | 150 +++++++++++--------------------------------------------- 1 file changed, 29 insertions(+), 121 deletions(-) (limited to 'src/eval/mod.rs') diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 98b0152c..5a67555c 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -14,6 +14,7 @@ mod collapse; mod func; mod ops; mod scope; +mod show; mod template; pub use array::*; @@ -23,6 +24,7 @@ pub use collapse::*; pub use dict::*; pub use func::*; pub use scope::*; +pub use show::*; pub use styles::*; pub use template::*; pub use value::*; @@ -33,34 +35,23 @@ use std::io; use std::mem; use std::path::PathBuf; -use once_cell::sync::Lazy; -use syntect::easy::HighlightLines; -use syntect::highlighting::{FontStyle, Highlighter, Style as SynStyle, Theme, ThemeSet}; -use syntect::parsing::SyntaxSet; use unicode_segmentation::UnicodeSegmentation; use crate::diag::{At, Error, StrResult, Trace, Tracepoint, TypResult}; -use crate::geom::{Angle, Color, Fractional, Length, Paint, Relative}; +use crate::geom::{Angle, Fractional, Length, Relative}; use crate::image::ImageStore; use crate::layout::Layout; -use crate::library::{self, DecoLine, TextNode}; +use crate::library::{self}; use crate::loading::Loader; -use crate::parse; use crate::source::{SourceId, SourceStore}; -use crate::syntax; use crate::syntax::ast::*; -use crate::syntax::{RedNode, Span, Spanned}; +use crate::syntax::{Span, Spanned}; use crate::util::{EcoString, RefMutExt}; use crate::Context; -static THEME: Lazy = - Lazy::new(|| ThemeSet::load_defaults().themes.remove("InspiredGitHub").unwrap()); - -static SYNTAXES: Lazy = Lazy::new(|| SyntaxSet::load_defaults_newlines()); - /// An evaluated module, ready for importing or conversion to a root layout /// tree. -#[derive(Debug, Default, Clone)] +#[derive(Debug, Clone)] pub struct Module { /// The top-level definitions that were bound in this module. pub scope: Scope, @@ -194,17 +185,13 @@ fn eval_markup( MarkupNode::Expr(Expr::Wrap(wrap)) => { let tail = eval_markup(ctx, nodes)?; ctx.scopes.def_mut(wrap.binding().take(), tail); - wrap.body().eval(ctx)?.show() + wrap.body().eval(ctx)?.display() } _ => node.eval(ctx)?, }); } - if seq.len() == 1 { - Ok(seq.into_iter().next().unwrap()) - } else { - Ok(Template::Sequence(seq)) - } + Ok(Template::sequence(seq)) } impl Eval for MarkupNode { @@ -223,7 +210,7 @@ impl Eval for MarkupNode { Self::Heading(heading) => heading.eval(ctx)?, Self::List(list) => list.eval(ctx)?, Self::Enum(enum_) => enum_.eval(ctx)?, - Self::Expr(expr) => expr.eval(ctx)?.show(), + Self::Expr(expr) => expr.eval(ctx)?.display(), }) } } @@ -232,7 +219,7 @@ impl Eval for StrongNode { type Output = Template; fn eval(&self, ctx: &mut EvalContext) -> TypResult { - Ok(self.body().eval(ctx)?.styled(TextNode::STRONG, true)) + Ok(Template::show(library::StrongNode(self.body().eval(ctx)?))) } } @@ -240,7 +227,7 @@ impl Eval for EmphNode { type Output = Template; fn eval(&self, ctx: &mut EvalContext) -> TypResult { - Ok(self.body().eval(ctx)?.styled(TextNode::EMPH, true)) + Ok(Template::show(library::EmphNode(self.body().eval(ctx)?))) } } @@ -248,104 +235,25 @@ impl Eval for RawNode { type Output = Template; fn eval(&self, _: &mut EvalContext) -> TypResult { - let code = self.highlighted(); - Ok(if self.block { Template::Block(code.pack()) } else { code }) - } -} - -impl RawNode { - /// Styled template for a code block, with optional syntax highlighting. - pub fn highlighted(&self) -> Template { - let mut seq: Vec