summaryrefslogtreecommitdiff
path: root/src/main.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/main.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/main.rs')
-rw-r--r--src/main.rs41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 91edff17..7891082d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -35,32 +35,35 @@ fn main() -> anyhow::Result<()> {
.wrap();
// Resolve the file id of the source file and read the file.
- let src_id = loader.resolve(src_path).context("source file not found")?;
+ let file = loader.resolve(src_path).context("source file not found")?;
let src = fs::read_to_string(&src_path)
.map_err(|_| anyhow!("failed to read source file"))?;
// Typeset.
let mut ctx = typst::Context::new(loader);
- let pass = ctx.typeset(src_id, &src);
+ match ctx.typeset(file, &src) {
+ // Export the PDF.
+ Ok(document) => {
+ let buffer = typst::export::pdf(&ctx, &document);
+ fs::write(&dest_path, buffer).context("failed to write PDF file")?;
+ }
- // Print diagnostics.
- let map = typst::parse::LineMap::new(&src);
- for diag in pass.diags {
- let start = map.location(diag.span.start).unwrap();
- let end = map.location(diag.span.end).unwrap();
- println!(
- "{}: {}:{}-{}: {}",
- diag.level,
- src_path.display(),
- start,
- end,
- diag.message,
- );
+ // Print diagnostics.
+ Err(errors) => {
+ let map = typst::parse::LineMap::new(&src);
+ for error in errors.iter() {
+ let start = map.location(error.span.start).unwrap();
+ let end = map.location(error.span.end).unwrap();
+ println!(
+ "Error: {}:{}-{}: {}",
+ src_path.display(),
+ start,
+ end,
+ error.message,
+ );
+ }
+ }
}
- // Export the PDF.
- let buffer = typst::export::pdf(&ctx, &pass.output);
- fs::write(&dest_path, buffer).context("failed to write PDF file")?;
-
Ok(())
}