summaryrefslogtreecommitdiff
path: root/src/lib.rs
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/lib.rs
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/lib.rs')
-rw-r--r--src/lib.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/lib.rs b/src/lib.rs
index da006333..be99fb58 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,9 +7,9 @@
//! module.
//! - **Evaluation:** The next step is to [evaluate] the syntax tree. This
//! computes the value of each node in the document and produces a [module].
-//! - **Execution:** Now, we can [execute] the parsed and evaluated module.
-//! This produces a [layout tree], a high-level, fully styled representation
-//! of the document. The nodes of this tree are self-contained and
+//! - **Execution:** Now, we can [execute] the parsed and evaluated module. This
+//! results in a [layout tree], a high-level, fully styled representation of
+//! the document. The nodes of this tree are self-contained and
//! order-independent and thus much better suited for layouting than the
//! syntax tree.
//! - **Layouting:** Next, the tree is [layouted] into a portable version of the
@@ -49,7 +49,7 @@ pub mod util;
use std::rc::Rc;
-use crate::diag::Pass;
+use crate::diag::TypResult;
use crate::eval::{ModuleCache, Scope};
use crate::exec::State;
use crate::font::FontCache;
@@ -100,19 +100,15 @@ impl Context {
/// The `file` identifies the source file and is used to resolve relative
/// paths (for importing and image loading).
///
- /// Returns a vector of frames representing individual pages alongside
- /// diagnostic information (errors and warnings).
- pub fn typeset(&mut self, file: FileId, src: &str) -> Pass<Vec<Rc<Frame>>> {
- let ast = parse::parse(src);
- let module = eval::eval(self, file, Rc::new(ast.output));
- let tree = exec::exec(self, &module.output.template);
- let frames = layout::layout(self, &tree.output);
-
- let mut diags = ast.diags;
- diags.extend(module.diags);
- diags.extend(tree.diags);
-
- Pass::new(frames, diags)
+ /// Returns either a vector of frames representing individual pages or
+ /// diagnostics in the form of a vector of error message with file and span
+ /// information.
+ pub fn typeset(&mut self, file: FileId, src: &str) -> TypResult<Vec<Rc<Frame>>> {
+ let ast = parse::parse(file, src)?;
+ let module = eval::eval(self, file, Rc::new(ast))?;
+ let tree = exec::exec(self, &module.template);
+ let frames = layout::layout(self, &tree);
+ Ok(frames)
}
}