tamer: parse::parser: Include object in parser trace

This information is likely redundant in a lowering pipeline, but is more
useful outside of such a pipeline.  It's also more clear.

`Object` does not implement `Display`, though, because that's too burdensome
for how it's currently used.  Many `Object`s are also `Token`s though and,
if fed to another `Parser` for lowering, it'll get `Display::fmt`'d.

DEV-7145
main
Mike Gerwitz 2022-07-22 12:51:05 -04:00
parent 4b5e51b0f0
commit 8f25c9ae0a
2 changed files with 24 additions and 2 deletions

View File

@ -316,6 +316,18 @@ impl<S: ParseState, I: TokenStream<S::Token>> Parser<S, I> {
la = data.lookahead_ref(),
);
if let Some(obj) = data.object_ref() {
// Note that `Object` does not implement `Display`,
// but you'll see a `Display` representation if the object
// is passed to another `Parser` as a `Token`.
eprint!(
"\
|
| ==> Yielded object:
| | {obj:?}\n",
);
}
if let Some(err) = data.err_ref() {
eprint!(
"\

View File

@ -146,10 +146,10 @@ pub(in super::super) enum TransitionData<S: ParseState> {
Dead(Lookahead<S::Token>),
}
#[cfg(any(test, feature = "parser-trace-stderr"))]
impl<S: ParseState> TransitionData<S> {
/// Reference to the token of lookahead,
/// if any.
#[cfg(any(test, feature = "parser-trace-stderr"))]
pub(in super::super) fn lookahead_ref(
&self,
) -> Option<&Lookahead<S::Token>> {
@ -160,9 +160,19 @@ impl<S: ParseState> TransitionData<S> {
}
}
/// Reference to parsed object,
/// if any.
pub(in super::super) fn object_ref(&self) -> Option<&S::Object> {
match self {
TransitionData::Result(Ok(ParseStatus::Object(obj)), _) => {
Some(obj)
}
_ => None,
}
}
/// Reference to parsing error,
/// if any.
#[cfg(any(test, feature = "parser-trace-stderr"))]
pub(in super::super) fn err_ref(&self) -> Option<&S::Error> {
match self {
TransitionData::Result(Err(e), _) => Some(e),