summaryrefslogtreecommitdiff
path: root/src/exec
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-30 18:04:08 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-30 18:49:19 +0200
commit1ee1d078e2480ddd08d40915bc7a74a8352acff0 (patch)
tree1e7ff367278a19fead3e404cf06d65bfb80a6cd9 /src/exec
parent42a27b48df427edf8dbb624c51551a90ecf2e7ea (diff)
Fatal errors
- Makes errors fatal, so that a phase is only reached when all previous phases were error-free - Parsing still recovers and can produce multiple errors - Evaluation fails fast and can thus produce only a single error (except for parse errors due to an import) - The single error that could occur during execution is removed for now - Removes Value::Error variant
Diffstat (limited to 'src/exec')
-rw-r--r--src/exec/context.rs21
-rw-r--r--src/exec/mod.rs4
2 files changed, 6 insertions, 19 deletions
diff --git a/src/exec/context.rs b/src/exec/context.rs
index 4d351692..2d419a56 100644
--- a/src/exec/context.rs
+++ b/src/exec/context.rs
@@ -2,13 +2,12 @@ use std::mem;
use std::rc::Rc;
use super::{Exec, ExecWithMap, State};
-use crate::diag::{Diag, DiagSet, Pass};
use crate::eval::{ExprMap, Template};
use crate::geom::{Align, Dir, Gen, GenAxis, Length, Linear, Sides, Size};
use crate::layout::{
LayoutNode, LayoutTree, PadNode, PageRun, ParChild, ParNode, StackChild, StackNode,
};
-use crate::syntax::{Span, SyntaxTree};
+use crate::syntax::SyntaxTree;
use crate::util::EcoString;
use crate::Context;
@@ -16,8 +15,6 @@ use crate::Context;
pub struct ExecContext {
/// The active execution state.
pub state: State,
- /// Execution diagnostics.
- pub diags: DiagSet,
/// The tree of finished page runs.
tree: LayoutTree,
/// When we are building the top-level stack, this contains metrics of the
@@ -32,18 +29,12 @@ impl ExecContext {
pub fn new(ctx: &mut Context) -> Self {
Self {
state: ctx.state.clone(),
- diags: DiagSet::new(),
tree: LayoutTree { runs: vec![] },
page: Some(PageBuilder::new(&ctx.state, true)),
stack: StackBuilder::new(&ctx.state),
}
}
- /// Add a diagnostic.
- pub fn diag(&mut self, diag: Diag) {
- self.diags.insert(diag);
- }
-
/// Execute a template and return the result as a stack node.
pub fn exec_template_stack(&mut self, template: &Template) -> StackNode {
self.exec_stack(|ctx| template.exec(ctx))
@@ -127,21 +118,19 @@ impl ExecContext {
}
/// Apply a forced page break.
- pub fn pagebreak(&mut self, keep: bool, hard: bool, span: Span) {
+ pub fn pagebreak(&mut self, keep: bool, hard: bool) {
if let Some(builder) = &mut self.page {
let page = mem::replace(builder, PageBuilder::new(&self.state, hard));
let stack = mem::replace(&mut self.stack, StackBuilder::new(&self.state));
self.tree.runs.extend(page.build(stack.build(), keep));
- } else {
- self.diag(error!(span, "cannot modify page from here"));
}
}
/// Finish execution and return the created layout tree.
- pub fn finish(mut self) -> Pass<LayoutTree> {
+ pub fn finish(mut self) -> LayoutTree {
assert!(self.page.is_some());
- self.pagebreak(true, false, Span::default());
- Pass::new(self.tree, self.diags)
+ self.pagebreak(true, false);
+ self.tree
}
fn make_text_node(&self, text: impl Into<EcoString>) -> ParChild {
diff --git a/src/exec/mod.rs b/src/exec/mod.rs
index 8bac76e8..762b555d 100644
--- a/src/exec/mod.rs
+++ b/src/exec/mod.rs
@@ -8,7 +8,6 @@ pub use state::*;
use std::fmt::Write;
-use crate::diag::Pass;
use crate::eval::{ExprMap, Template, TemplateFunc, TemplateNode, TemplateTree, Value};
use crate::geom::Gen;
use crate::layout::{LayoutTree, StackChild, StackNode};
@@ -18,7 +17,7 @@ use crate::util::EcoString;
use crate::Context;
/// Execute a template to produce a layout tree.
-pub fn exec(ctx: &mut Context, template: &Template) -> Pass<LayoutTree> {
+pub fn exec(ctx: &mut Context, template: &Template) -> LayoutTree {
let mut ctx = ExecContext::new(ctx);
template.exec(&mut ctx);
ctx.finish()
@@ -138,7 +137,6 @@ impl Exec for Value {
Value::Float(v) => ctx.push_text(pretty(v)),
Value::Str(v) => ctx.push_text(v),
Value::Template(v) => v.exec(ctx),
- Value::Error => {}
// For values which can't be shown "naturally", we print the
// representation in monospace.
other => ctx.push_monospace_text(pretty(other)),