[NTG-context] Off-topic: Struggles with LPEG grammar

Mojca Miklavec mojca.miklavec.lists at gmail.com
Mon Dec 21 15:10:03 CET 2020


Thanks to both Taco and Arthur for clarifying this and pointing out
the difference between PEG and PCRE.

I'll put some links like
on my reading list and try to understand it more thoroughly than I do
at the moment.
After that I'll probably need to re-read Taco's answer a couple more
times, and probably write some parsing grammar as an exercise, but
I'll eventually get there :)

Just a correction of my previous statement. The following doesn't
really work either:
    lpeg.P('b') + lpeg.P('bb') + lpeg.P('bbb')
it just happened to work in one particular case on my minimal example,
but it doesn't help in general.
That's probably expected based on what Arthur and Taco explained to me.

> In your example, the fact that you even considered ^1 means that you were still thinking too much in terms of regular expressions,

In reality it just means that I was trying to add a new rule to solve
the second part of the puzzle (hidden on the website until you solve
the first part), which read something like
    6: 3 | 3 6
which would in theory be translated into something like
    r6 = lpeg.V"r3" + lpeg.V"r3" * lpeg.V"r6",
if PEGs worked the way I imagined they worked, that is. Apparently they don't :)

It seemed so obvious, but it would be too easy if it was true ;),
so it will force me to solve it "ab initio" (as it was initially meant) anyway.

Thanks a lot to everyone for the extra patience to explain me those
basic principles & differences,

More information about the ntg-context mailing list