tamer: pipeline: Allow reporting on entire Result
The report acts as the sink for `load_xmlo` and `parse_package_xml`. At the moment, the type is `()`, and so there's nothing to report on but the error. But the idea is to add logging via `AirAggregate::Object`, which is currently just `()`. This change therefore is only a refactoring---it changes no functionality but sets up for future changes. This also introduces consistency with `lower_xmli` in use of `terminal` for the final operation. DEV-13162main
parent
0f20f22cfb
commit
f34f2644e9
|
@ -119,13 +119,15 @@ fn compile<R: Reporter>(
|
|||
|
||||
let mut ebuf = String::new();
|
||||
|
||||
let report_err = |e: RecoverableError| {
|
||||
// See below note about buffering.
|
||||
ebuf.clear();
|
||||
writeln!(ebuf, "{}", reporter.render(&e))?;
|
||||
println!("{ebuf}");
|
||||
let report_err = |result: Result<(), RecoverableError>| {
|
||||
result.or_else(|e| {
|
||||
// See below note about buffering.
|
||||
ebuf.clear();
|
||||
writeln!(ebuf, "{}", reporter.render(&e))?;
|
||||
println!("{ebuf}");
|
||||
|
||||
Ok::<_, UnrecoverableError>(())
|
||||
Ok::<_, UnrecoverableError>(())
|
||||
})
|
||||
};
|
||||
|
||||
// TODO: We're just echoing back out XIR,
|
||||
|
|
|
@ -49,6 +49,7 @@ use crate::{
|
|||
};
|
||||
use fxhash::FxBuildHasher;
|
||||
use std::{
|
||||
convert::identity,
|
||||
error::Error,
|
||||
fmt::{self, Display},
|
||||
fs,
|
||||
|
@ -106,7 +107,7 @@ fn load_xmlo<P: AsRef<Path>, S: Escaper>(
|
|||
let src = &mut lowerable(XmlXirReader::new(file, escaper, ctx));
|
||||
|
||||
let (mut air_ctx, mut state) =
|
||||
pipeline::load_xmlo::<TameldError, _>(src, air_ctx, state, Err)?;
|
||||
pipeline::load_xmlo::<TameldError, _>(src, air_ctx, state, identity)?;
|
||||
|
||||
let mut dir = path;
|
||||
dir.pop();
|
||||
|
|
|
@ -77,7 +77,7 @@ pub fn load_xmlo<ER: Diagnostic, EU: Diagnostic>(
|
|||
src: impl LowerSource<UnknownToken, XirToken, XirError>,
|
||||
air_ctx: AirAggregateCtx,
|
||||
xmlo_ctx: XmloAirContext,
|
||||
mut report_err: impl FnMut(ER) -> Result<(), EU>,
|
||||
report: impl FnMut(Result<(), ER>) -> Result<(), EU>,
|
||||
) -> Result<(AirAggregateCtx, XmloAirContext), EU>
|
||||
where
|
||||
ER: From<ParseError<UnknownToken, XirError>>
|
||||
|
@ -107,13 +107,7 @@ where
|
|||
|
||||
Lower::<XmloReader, XmloToAir, _>::lower_with_context(&mut iter, xmlo_ctx, |air| {
|
||||
Lower::<XmloToAir, AirAggregate, _>::lower_with_context(air, air_ctx, |end| {
|
||||
end.fold(Ok(()), |x, result| match result {
|
||||
Ok(_) => x,
|
||||
Err(e) => {
|
||||
report_err(e)?;
|
||||
x
|
||||
}
|
||||
})
|
||||
terminal::<AirAggregate, _>(end).try_for_each(report)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -129,7 +123,7 @@ where
|
|||
pub fn parse_package_xml<ER: Diagnostic, EU: Diagnostic>(
|
||||
src: impl LowerSource<UnknownToken, XirToken, XirError>,
|
||||
air_ctx: AirAggregateCtx,
|
||||
mut report_err: impl FnMut(ER) -> Result<(), EU>,
|
||||
report: impl FnMut(Result<(), ER>) -> Result<(), EU>,
|
||||
) -> Result<AirAggregateCtx, EU>
|
||||
where
|
||||
ER: From<ParseError<UnknownToken, XirError>>
|
||||
|
@ -152,13 +146,7 @@ where
|
|||
Lower::<TplShortDesugar, InterpolateNir, _>::lower(nir, |nir| {
|
||||
Lower::<InterpolateNir, NirToAir, _>::lower(nir, |air| {
|
||||
Lower::<NirToAir, AirAggregate, _>::lower_with_context(air, air_ctx, |end| {
|
||||
end.fold(Ok(()), |x, result| match result {
|
||||
Ok(_) => x,
|
||||
Err(e) => {
|
||||
report_err(e)?;
|
||||
x
|
||||
}
|
||||
})
|
||||
terminal::<AirAggregate, _>(end).try_for_each(report)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue