0

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.

brooks94
  • 3,836
  • 4
  • 30
  • 57

1 Answers1

0

There exists Camlp4Tracer for ordinary function calls, maybe you could draw an inspiration from it and write a Camlp4Filter for the camlp4 grammar itself.. I am not to be held responsible if you go insane during that endeavour %)

ygrek
  • 6,656
  • 22
  • 29