tamer: asg::graph::object::xir: New context to hold stack state
This (a) hold the state of a stack that I can populate with tokens rather than introducing a state for every single e.g. attribute and such on elements (so, more like the `xmle` XIR lowering). It also hides the obvious awkwardness of the `&mut &'a Asg`, but that's not the intent of it. DEV-13708main
parent
fe925db47d
commit
7efd08a699
|
@ -66,20 +66,12 @@ impl<'a> ParseState for AsgTreeToXirf<'a> {
|
|||
type Token = TreeWalkRel;
|
||||
type Object = XirfToken<Text>;
|
||||
type Error = Infallible;
|
||||
|
||||
/// Read-only reference to the [`Asg`].
|
||||
///
|
||||
/// This creates an awkward `&mut &'a Asg` in the signature of
|
||||
/// [`Self::parse_token`],
|
||||
/// but Rust's auto-deref makes use of it transparent.
|
||||
/// The use of the context in this way is a bit of a kluge that maybe
|
||||
/// will be improved upon in the future.
|
||||
type Context = &'a Asg;
|
||||
type Context = TreeContext<'a>;
|
||||
|
||||
fn parse_token(
|
||||
self,
|
||||
tok: Self::Token,
|
||||
asg: &mut &'a Asg,
|
||||
TreeContext(_, asg): &mut TreeContext,
|
||||
) -> TransitionResult<Self::Super> {
|
||||
use ObjectRelTy as Ty;
|
||||
|
||||
|
@ -110,3 +102,14 @@ impl<'a> ParseState for AsgTreeToXirf<'a> {
|
|||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TreeContext<'a>(StackPlaceholder, &'a Asg);
|
||||
|
||||
type StackPlaceholder = ();
|
||||
|
||||
impl<'a> From<&'a Asg> for TreeContext<'a> {
|
||||
fn from(asg: &'a Asg) -> Self {
|
||||
Self(Default::default(), asg)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue