tamer: parse::lower:::Lower::lower: Implement in terms of lower_with_context
This is just a special case of lowering with a context, and maintaining two separate implementations has resulted in divergence. I don't recall why I didn't do this previously, though it's possible that the lowering pipeline was in a state that made it more difficult to do (e.g. with error handling). DEV-13708main
parent
6db70385d0
commit
fe925db47d
|
@ -121,17 +121,11 @@ where
|
|||
) -> Result<U, E>
|
||||
where
|
||||
Self: Iterator<Item = WidenedParsedResult<S, EW>> + Sized,
|
||||
E: Diagnostic + From<FinalizeError>,
|
||||
<LS as ParseState>::Context: Default,
|
||||
{
|
||||
let lower = LS::parse(iter::empty());
|
||||
let mut iter = LowerIter {
|
||||
lower,
|
||||
toks: self,
|
||||
_phantom: PhantomData::default(),
|
||||
};
|
||||
f(&mut iter)
|
||||
|
||||
// TODO: Finalize!
|
||||
self.lower_with_context(<LS as ParseState>::Context::default(), f)
|
||||
.map(|(val, _ctx)| val)
|
||||
}
|
||||
|
||||
/// Perform a lowering operation between two parsers where the context
|
||||
|
@ -144,14 +138,14 @@ where
|
|||
#[inline]
|
||||
fn lower_with_context<U, E>(
|
||||
&mut self,
|
||||
ctx: LS::Context,
|
||||
ctx: impl Into<LS::Context>,
|
||||
f: impl FnOnce(&mut LowerIter<S, Self, LS, EW>) -> Result<U, E>,
|
||||
) -> Result<(U, LS::Context), E>
|
||||
where
|
||||
Self: Iterator<Item = WidenedParsedResult<S, EW>> + Sized,
|
||||
E: Diagnostic + From<FinalizeError>,
|
||||
{
|
||||
let lower = LS::parse_with_context(iter::empty(), ctx);
|
||||
let lower = LS::parse_with_context(iter::empty(), ctx.into());
|
||||
let mut iter = LowerIter {
|
||||
lower,
|
||||
toks: self,
|
||||
|
@ -407,6 +401,12 @@ mod test {
|
|||
let given = 27; // some value
|
||||
let toks = vec![StubToken::YieldWithLookahead(given)];
|
||||
|
||||
impl From<FinalizeError> for StubError {
|
||||
fn from(_: FinalizeError) -> Self {
|
||||
unreachable!("not expected to be used by this test")
|
||||
}
|
||||
}
|
||||
|
||||
Lower::<StubEchoParseState, StubParseState, _>::lower::<_, StubError>(
|
||||
&mut StubEchoParseState::parse(toks.into_iter()),
|
||||
|sut| {
|
||||
|
|
Loading…
Reference in New Issue