librelist archives

« back to archive

Detecting the last successfully matched rule

Detecting the last successfully matched rule

From:
Gabe Hollombe
Date:
2013-10-16 @ 03:25
Hey there,

Disclaimer: I'm new to Parslet, and PEGs in general.

When working on creating a parser with Parslet, sometimes I'm bitten by the
fact that one of my rules is being more 'greedy' than it should be.  I
mean, it's working as-written, but I should have been more specific when
describing the rule.

So I'm wondering, is there a way I can ask Parslet to show me the last
matched rule when it encounters parsing errors?  That way, I'd know right
away that it matched a needlessly greedy rule that I wasn't expecting.

-g

Re: [ruby.parslet] Detecting the last successfully matched rule

From:
Kaspar Schiess
Date:
2013-10-16 @ 12:41
Hi Gabe,

> So I'm wondering, is there a way I can ask Parslet to show me the last 
> matched rule when it encounters parsing errors?  That way,
> I'd know right away that it matched a needlessly greedy rule that I 
> wasn't expecting.

No, currently there is not.

A thought: While your input is linear, your parser is not. The rule 
'before' might actually be hard to define. It involves some kind of 
sequence/repetition, but subsequent sequences might not be on the same 
level at all…

This example 
(https://github.com/kschiess/parslet/blob/master/example/deepest_errors.rb) 
shows how to use a different error reporter than the one that is 
default. It uses another strategy for keeping track of errors. Maybe 
that output helps?

(Just looking at the error reporter API might inspire you to build a 
custom error reporter for your case. )

best of luck
kaspar

Re: [ruby.parslet] Detecting the last successfully matched rule

From:
Gabe Hollombe
Date:
2013-10-17 @ 03:08
Thanks very much, Kaspar.  I'll take a look at the error reporter API and
possibly get my hands dirty, if needed. =-)

-g


On Wed, Oct 16, 2013 at 8:41 PM, Kaspar Schiess <kaspar.schiess@absurd.li>wrote:

>  Hi Gabe,
>
> So I'm wondering, is there a way I can ask Parslet to show me the last
> matched rule when it encounters parsing errors?  That way,
> I'd know right away that it matched a needlessly greedy rule that I wasn't
> expecting.
>
> No, currently there is not.
>
> A thought: While your input is linear, your parser is not. The rule
> 'before' might actually be hard to define. It involves some kind of
> sequence/repetition, but subsequent sequences might not be on the same
> level at all…
>
> This example (
> https://github.com/kschiess/parslet/blob/master/example/deepest_errors.rb)
> shows how to use a different error reporter than the one that is default.
> It uses another strategy for keeping track of errors. Maybe that output
> helps?
>
> (Just looking at the error reporter API might inspire you to build a
> custom error reporter for your case. )
>
> best of luck
> kaspar
>