tamer: parse::transition::Lookahead: ParseState=>Token type param

Having the lookahead token generic over the `ParseState` was a pain in the
ass for stitching, since they shared the same token type but not the same
parser.  I don't expect there to be any need to be able to infer other
parser-related types for a token of lookahead, so I'd rather just make my
life easier until such a thing is needed.

DEV-7145
main
Mike Gerwitz 2022-07-13 10:13:35 -04:00
parent bd783ac08b
commit c9b3b84f90
3 changed files with 9 additions and 12 deletions

View File

@ -85,7 +85,7 @@ pub struct Parser<S: ParseState, I: TokenStream<S::Token>> {
///
/// See [`take_lookahead_tok`](Parser::take_lookahead_tok) for more
/// information.
lookahead: Option<Lookahead<S>>,
lookahead: Option<Lookahead<S::Token>>,
/// Parsing automaton.
///

View File

@ -249,7 +249,7 @@ pub trait ParseState: PartialEq + Eq + Display + Debug + Sized {
Ok(Obj(obj)) => Ok(Obj(obj.into())),
Err(e) => Err(e.into()),
},
lookahead.map(|Lookahead(la)| Lookahead(la)),
lookahead,
),
),
}
@ -292,10 +292,7 @@ pub trait ParseState: PartialEq + Eq + Display + Debug + Sized {
TransitionData::Result(Ok(Obj(obj)), lookahead) => {
TransitionResult(
into(newst, Some(obj), env),
TransitionData::Result(
Ok(Incomplete),
lookahead.map(|Lookahead(la)| Lookahead(la)),
),
TransitionData::Result(Ok(Incomplete), lookahead),
)
}
@ -306,7 +303,7 @@ pub trait ParseState: PartialEq + Eq + Display + Debug + Sized {
Ok(_) => Ok(Incomplete),
Err(e) => Err(e.into()),
},
lookahead.map(|Lookahead(la)| Lookahead(la)),
lookahead,
),
),
}

View File

@ -19,7 +19,7 @@
//! State transitions for parser automata.
use super::{ParseState, ParseStateResult, ParseStatus};
use super::{ParseState, ParseStateResult, ParseStatus, Token};
use std::{
convert::Infallible,
hint::unreachable_unchecked,
@ -27,7 +27,7 @@ use std::{
};
#[cfg(doc)]
use super::{Parser, Token};
use super::Parser;
/// A state transition with associated data.
///
@ -86,7 +86,7 @@ impl<S: ParseState> TransitionResult<S> {
/// Token to use as a lookahead token in place of the next token from the
/// input stream.
#[derive(Debug, PartialEq)]
pub struct Lookahead<S: ParseState>(pub(in super::super) S::Token);
pub struct Lookahead<T: Token>(pub(in super::super) T);
/// Information about the state transition.
///
@ -103,7 +103,7 @@ pub(in super::super) enum TransitionData<S: ParseState> {
/// successful [`ParseStateResult`]---the
/// parser may choose to successfully transition into an error
/// recovery state to accommodate future tokens.
Result(ParseStateResult<S>, Option<Lookahead<S>>),
Result(ParseStateResult<S>, Option<Lookahead<S::Token>>),
/// No valid state transition exists from the current state for the
/// given input token,
@ -124,7 +124,7 @@ pub(in super::super) enum TransitionData<S: ParseState> {
/// and may lead to finalization of the parser.
/// If a parser intends to do additional work,
/// it should return an error instead via [`TransitionData::Result`].
Dead(Lookahead<S>),
Dead(Lookahead<S::Token>),
}
/// A verb denoting a state transition.