Where you said:

  expr = a (dot a / left a right)* dot a

The following should work:

  expr = a (dot a &(dot a) / left a right &(dot a))* dot a

But it depends a little on what your actual use case is.  What
I did here was insist that either case of the choice operator
require but leave the rest of the needed expression.  This should
prevent the (dot a)* from being too greedy, or in your description,
it will make it properly backtrack.

Untested, as this is off the top of my head.  Mistakes entirely
possible.

-Alan

On Tue, Oct 30, 2012 at 07:12:23PM +0400, Alexey Shamrin wrote:
> Hello,
> 
> I'm trying to write a PEG grammar that would match this input:
> 
>   a.a(a).a
> 
> And would not match this input:
> 
>   a.a(a)
> 
> I want my input to always end with ".a".
> 
> I tried the following grammar in PEG.js [1] and language.js [2]:
> 
>   start = expr !.
>   expr = a (dot a / left a right)* dot a
>   a = 'a'
>   dot = '.'
>   left = '('
>   right = ')'
> 
> But it doesn't work. In PEG.js my first input fails with "Expected "("
> or "." but end of input found.".
> 
> It seems PEG doesn't try to backtrack at this point. Why doesn't it?
> What grammar can work for me?
> 
> [1]: http://pegjs.majda.cz/online
> [2]: http://languagejs.com/
> 
> Alexey
> 
> _______________________________________________
> PEG mailing list
> PEG@lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/peg

-- 
.i ma'a lo bradi cu penmi gi'e du

_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to