find which rule(s) could not be matched

35 views
Skip to first unread message

Joshua Moore Work

unread,
Oct 16, 2011, 10:05:22 PM10/16/11
to treet...@googlegroups.com
Hi,

I am working with treetop in order to parse an SQL log. i was wondering if the parsing fails is there any way to know which rule(s) it was trying to match when it failed?

Thanks,

Josh

Clifford Heath

unread,
Oct 16, 2011, 10:59:11 PM10/16/11
to treet...@googlegroups.com
On 17/10/2011, at 1:05 PM, Joshua Moore Work wrote:
> I am working with treetop in order to parse an SQL log. i was wondering if the parsing fails is there any way to know which rule(s) it was trying to match when it failed?

Because PEGs have unlimited backtracking, there is no clearly-defined meaning for "which rule failed".
The "failure_reason" is constructed from the terminal rules that failed at the *furthermost* point reached.

It's not hard to hack Treetop::Runtime::TerminalParseFailure#initialize to save the stack trace returned
by "caller" in an instance variable, which allows you to inspect what the stack trace was at the time of
each such failure. Hellishly expensive in memory, but it enables you to look back and see what the rule
nesting was.

Clifford Heath.

Reply all
Reply to author
Forward
0 new messages