diff --git a/tamer/src/parse/state.rs b/tamer/src/parse/state.rs index b0e10f22..e6668d7c 100644 --- a/tamer/src/parse/state.rs +++ b/tamer/src/parse/state.rs @@ -302,20 +302,9 @@ where TransitionData::Dead(Lookahead(lookahead)) => { dead().incomplete().with_lookahead(lookahead) } - TransitionData::Result(result, lookahead) => TransitionResult( - into(newst).into_super(), - TransitionData::Result( - match result { - Ok(Incomplete) => Ok(Incomplete), - Ok(Obj(obj)) => Ok(Obj(obj.into())), - // First convert the error into `SP::Error`, - // and then `SP::Super::Error` - // (which will be the same type if SP is closed). - Err(e) => Err(e.into().into()), - }, - lookahead, - ), - ), + TransitionData::Result(..) => { + TransitionResult(into(newst).into_super(), data.inner_into()) + } } } diff --git a/tamer/src/parse/state/transition.rs b/tamer/src/parse/state/transition.rs index 1af68ea0..b8950dca 100644 --- a/tamer/src/parse/state/transition.rs +++ b/tamer/src/parse/state/transition.rs @@ -20,7 +20,8 @@ //! State transitions for parser automata. use super::{ - ClosedParseState, ParseState, ParseStateResult, ParseStatus, Token, + ClosedParseState, ParseState, ParseStateResult, ParseStatus, + StitchableParseState, Token, }; use std::{ convert::Infallible, @@ -306,6 +307,33 @@ impl TransitionData { Dead(la) => Dead(la), } } + + /// Transform inner types using [`Into`] such that they are compatible + /// with the superstate of `SB`. + pub fn inner_into( + self, + ) -> TransitionData<::Super> + where + S: StitchableParseState, + { + use ParseStatus::{Incomplete, Object}; + use TransitionData::*; + + match self { + Dead(la) => Dead(la), + Result(result, la) => Result( + match result { + Ok(Incomplete) => Ok(Incomplete), + Ok(Object(obj)) => Ok(Object(obj.into())), + // First convert the error into `SB::Error`, + // and then `SP::Super::Error` + // (which will be the same type if SB is closed). + Err(e) => Err(e.into().into()), + }, + la, + ), + } + } } /// A verb denoting a state transition.