tamer: parse::trace: Include context

This is something that I had apparently forgotten to do, but is now useful
in debugging `ele_parse!` issues with the trampoline.

DEV-7145
main
Mike Gerwitz 2022-08-11 13:47:26 -04:00
parent 54d8348e95
commit a4419413fb
2 changed files with 25 additions and 6 deletions

View File

@ -260,8 +260,11 @@ impl<S: ClosedParseState, I: TokenStream<S::Token>> Parser<S, I> {
"lookahead token is available but was not consumed",
);
self.tracer
.trace_tok_begin(self.state.as_ref().unwrap(), &tok);
self.tracer.trace_tok_begin(
self.state.as_ref().unwrap(),
&tok,
&self.ctx,
);
// Parse a single token and perform the requested state transition.
//
@ -279,7 +282,7 @@ impl<S: ClosedParseState, I: TokenStream<S::Token>> Parser<S, I> {
let TransitionResult(Transition(state), data) =
self.state.take().unwrap().parse_token(tok, &mut self.ctx);
self.tracer.trace_tok_end(&state, &data);
self.tracer.trace_tok_end(&state, &data, &self.ctx);
self.state.replace(state);
use ParseStatus::{Incomplete, Object};

View File

@ -47,7 +47,12 @@ pub(super) trait ParserTrace: Default {
///
/// There is no means to return an error and a failure to output the
/// trace should not interrupt processing.
fn trace_tok_begin<S: ParseState>(&mut self, st_orig: &S, tok: &S::Token);
fn trace_tok_begin<S: ParseState>(
&mut self,
st_orig: &S,
tok: &S::Token,
ctx: &S::Context,
);
/// Output the lower portion of a token trace.
///
@ -60,6 +65,7 @@ pub(super) trait ParserTrace: Default {
&mut self,
st_new: &S,
data: &TransitionData<S>,
ctx: &S::Context,
);
}
@ -75,6 +81,7 @@ impl ParserTrace for VoidTrace {
&mut self,
_st_orig: &S,
_tok: &S::Token,
_ctx: &S::Context,
) {
// Do nothing at all.
}
@ -83,6 +90,7 @@ impl ParserTrace for VoidTrace {
&mut self,
_st_new: &S,
_data: &TransitionData<S>,
_ctx: &S::Context,
) {
// Do nothing at all.
}
@ -101,12 +109,18 @@ impl ParserTrace for VoidTrace {
pub struct HumanReadableTrace<const REASON: &'static str>;
impl<const REASON: &'static str> ParserTrace for HumanReadableTrace<REASON> {
fn trace_tok_begin<S: ParseState>(&mut self, st_orig: &S, tok: &S::Token) {
fn trace_tok_begin<S: ParseState>(
&mut self,
st_orig: &S,
tok: &S::Token,
ctx: &S::Context,
) {
eprint!(
"\
[Parser::feed_tok] (input IR: {ir})
| ==> Parser before tok is {st_orig}.
| | {st_orig:?}
| | Context: {ctx:?}
|
| ==> {ir} tok: {tok}
| | {tok:?}
@ -119,12 +133,14 @@ impl<const REASON: &'static str> ParserTrace for HumanReadableTrace<REASON> {
&mut self,
st_new: &S,
data: &TransitionData<S>,
ctx: &S::Context,
) {
eprint!(
"\
| ==> Parser after tok is {st_new}.
| | {st_new:?}
| | Lookahead: {la:?}\n",
| | Lookahead: {la:?}
| | Context: {ctx:?}\n",
la = data.lookahead_ref(),
);