I'm writing a simple parser with Camlp4. The complexity is starting to get to the point where I am having trouble reasoning about the exact parse sequence. What would be the best way to produce a "trace" of the parse that includes the tokens consumed and the rules matched.
E.g. the following parser fragment:
let parse_func_call = parser
| [< 'Token.Ident id; 'Token.LParen; 'Token.Ident id; 'Token.RParen >] -> ...
Might output a trace fragment like:
CONSUMED Ident
MATCHED parse_func_call
CONSUMED LParen
CONSUMED Ident
CONSUMED RParen
It doesn't appear that there's any such thing built in to Camlp4, so I'm wondering if its possible.