From af1715ef91acacaaefe2dfd0c53728683c763e99 Mon Sep 17 00:00:00 2001 From: Mark <> Date: Wed, 26 Jun 2024 21:05:19 +0200 Subject: [PATCH] fix pretty_print_to --- mers_lib/Cargo.toml | 2 +- mers_lib/src/pretty_print.rs | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mers_lib/Cargo.toml b/mers_lib/Cargo.toml index 005292b..8724d14 100755 --- a/mers_lib/Cargo.toml +++ b/mers_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mers_lib" -version = "0.8.20" +version = "0.8.21" edition = "2021" license = "MIT OR Apache-2.0" description = "library to use the mers language in other projects" diff --git a/mers_lib/src/pretty_print.rs b/mers_lib/src/pretty_print.rs index 8fc13d0..52c59aa 100644 --- a/mers_lib/src/pretty_print.rs +++ b/mers_lib/src/pretty_print.rs @@ -1,27 +1,28 @@ use std::{io::Write, process::exit, sync::Arc}; use crate::{ + errors::CheckError, prelude_compile::{parse, Source}, theme::ThemeGen, }; #[cfg(feature = "ecolor-term")] pub fn pretty_print(src: Source) { - pretty_print_to(src, &mut std::io::stdout(), DefaultTheme) + if let Err(e) = pretty_print_to(src, &mut std::io::stdout(), DefaultTheme) { + eprintln!("{e:?}"); + exit(28); + } } /// to print to stdout, use `pretty_print` (available only with the `ecolor-term` feature) -pub fn pretty_print_to(mut src: Source, out: &mut O, theme: impl FTheme) { +pub fn pretty_print_to( + mut src: Source, + out: &mut O, + theme: impl FTheme, +) -> Result<(), CheckError> { let srca = Arc::new(src.clone()); - match parse(&mut src, &srca) { - Err(e) => { - eprintln!("{e:?}"); - exit(28); - } - Ok(parsed) => { - print_parsed(&srca, parsed.as_ref(), out, theme); - } - } + let parsed = parse(&mut src, &srca)?; + print_parsed(&srca, parsed.as_ref(), out, theme); } pub enum AbstractColor {