From b5187de5dcc2711ca51c3e36d99cbb77e79b46ba Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 31 May 2023 15:00:47 -0400 Subject: [PATCH] tamer: pipeline::load_xmlo: Accept reporter This makes the API of `load_xmlo` much closer to `parse_package_xml`, both accepting a reporter and distinguishing between recoverable and unrecoverable errors. The linker still does not use a reporter and still fails on the first error, as before; I wanted to keep this change small. DEV-13162 --- tamer/src/bin/tamec.rs | 4 ++-- tamer/src/ld/poc.rs | 2 +- tamer/src/pipeline.rs | 31 +++++++++++++++++-------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tamer/src/bin/tamec.rs b/tamer/src/bin/tamec.rs index c88d0fcc..bdc46caf 100644 --- a/tamer/src/bin/tamec.rs +++ b/tamer/src/bin/tamec.rs @@ -119,10 +119,10 @@ fn compile( let mut ebuf = String::new(); - let report_err = |e: &RecoverableError| { + let report_err = |e: RecoverableError| { // See below note about buffering. ebuf.clear(); - writeln!(ebuf, "{}", reporter.render(e))?; + writeln!(ebuf, "{}", reporter.render(&e))?; println!("{ebuf}"); Ok::<_, UnrecoverableError>(()) diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs index e2209d19..b343236f 100644 --- a/tamer/src/ld/poc.rs +++ b/tamer/src/ld/poc.rs @@ -106,7 +106,7 @@ fn load_xmlo, S: Escaper>( let src = &mut lowerable(XmlXirReader::new(file, escaper, ctx)); let (mut air_ctx, mut state) = - pipeline::load_xmlo::(src, air_ctx, state)?; + pipeline::load_xmlo::(src, air_ctx, state, Err)?; let mut dir = path; dir.pop(); diff --git a/tamer/src/pipeline.rs b/tamer/src/pipeline.rs index 4153efad..07e62743 100644 --- a/tamer/src/pipeline.rs +++ b/tamer/src/pipeline.rs @@ -73,26 +73,27 @@ use crate::{ /// TODO: To re-use this in `tamec` we want to be able to ignore fragments. /// /// TODO: More documentation once this has been further cleaned up. -pub fn load_xmlo( +pub fn load_xmlo( src: impl LowerSource, air_ctx: AirAggregateCtx, xmlo_ctx: XmloAirContext, + mut report_err: impl FnMut(ER) -> Result<(), EU>, ) -> Result<(AirAggregateCtx, XmloAirContext), EU> where - EU: From> + ER: From> + FromParseError> + FromParseError + FromParseError - + FromParseError - + From, + + FromParseError, + EU: From, { // TODO: This entire block is a WIP and will be incrementally // abstracted away. Lower::< ParsedObject, PartialXirToXirf<4, Text>, - EU, - >::lower(&mut src.map(|result| result.map_err(EU::from)), |toks| { + _, + >::lower(&mut src.map(|result| result.map_err(ER::from)), |toks| { Lower::, XmloReader, _>::lower(toks, |xmlo| { let mut iter = xmlo.scan(false, |st, rtok| match st { true => None, @@ -112,15 +113,17 @@ where air, air_ctx, |end| { - for result in end { - let _ = result?; - } - - Ok::<_, EU>(()) + end.fold(Ok::<_, EU>(()), |x, result| match result { + Ok(_) => x, + Err(e) => { + report_err(e)?; + x + } + }) }, )?; - Ok::<_, EU>(air_ctx) + Ok(air_ctx) }, ) }) @@ -134,7 +137,7 @@ where pub fn parse_package_xml( src: impl LowerSource, air_ctx: AirAggregateCtx, - mut report_err: impl FnMut(&ER) -> Result<(), EU>, + mut report_err: impl FnMut(ER) -> Result<(), EU>, ) -> Result where ER: From> @@ -160,7 +163,7 @@ where end.fold(Ok(()), |x, result| match result { Ok(_) => x, Err(e) => { - report_err(&e)?; + report_err(e)?; x } })