tamer: parse::state: Begin to tame delegation methods
These delegation methods have been a pain in my ass for quite some time, and their lack of generalization makes the introduction of new delegation methods (in the general sense, not necessarily trait methods) very tedious and prone to inconsistencies. I'm going to progressively refactor them in separate commits so it's clear what I'm doing, primarily for future me to reference if need be. DEV-13156main
parent
fc425ff1d5
commit
a17e53258b
|
@ -302,20 +302,9 @@ where
|
||||||
TransitionData::Dead(Lookahead(lookahead)) => {
|
TransitionData::Dead(Lookahead(lookahead)) => {
|
||||||
dead().incomplete().with_lookahead(lookahead)
|
dead().incomplete().with_lookahead(lookahead)
|
||||||
}
|
}
|
||||||
TransitionData::Result(result, lookahead) => TransitionResult(
|
TransitionData::Result(..) => {
|
||||||
into(newst).into_super(),
|
TransitionResult(into(newst).into_super(), data.inner_into())
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
//! State transitions for parser automata.
|
//! State transitions for parser automata.
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ClosedParseState, ParseState, ParseStateResult, ParseStatus, Token,
|
ClosedParseState, ParseState, ParseStateResult, ParseStatus,
|
||||||
|
StitchableParseState, Token,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
|
@ -306,6 +307,33 @@ impl<S: ParseState> TransitionData<S> {
|
||||||
Dead(la) => Dead(la),
|
Dead(la) => Dead(la),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transform inner types using [`Into`] such that they are compatible
|
||||||
|
/// with the superstate of `SB`.
|
||||||
|
pub fn inner_into<SB: ParseState>(
|
||||||
|
self,
|
||||||
|
) -> TransitionData<<SB as ParseState>::Super>
|
||||||
|
where
|
||||||
|
S: StitchableParseState<SB>,
|
||||||
|
{
|
||||||
|
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.
|
/// A verb denoting a state transition.
|
||||||
|
|
Loading…
Reference in New Issue