Alan, unfortunately this would not match "a.a(a).a", because ".a(a)" does not match "dot a &(dot a)".
Fortunately, there's a solution, that should work in general. Alexey wants the string to always end in ".a". I can think of two ways to accomplish this: expr = a (dot a &. / left a right &.)* dot a Or, expr = a rest rest = dot a rest / left a right rest / dot a I also haven't tested this. The second version should allow you to put "expr" in the middle of a larger grammar. The first version requires "expr" to be at the end of the string. Take care, Francisco On Tue, Oct 30, 2012 at 11:23 AM, Alan Post <[email protected]> wrote: > 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 >> [email protected] >> https://lists.csail.mit.edu/mailman/listinfo/peg > > -- > .i ma'a lo bradi cu penmi gi'e du > > _______________________________________________ > PEG mailing list > [email protected] > https://lists.csail.mit.edu/mailman/listinfo/peg _______________________________________________ PEG mailing list [email protected] https://lists.csail.mit.edu/mailman/listinfo/peg
