[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lpeg practices
- From: William Ahern <william@...>
- Date: Tue, 12 Jun 2012 14:16:07 -0700
On Tue, Jun 12, 2012 at 01:10:12PM +0100, Gavin Wraith wrote:
> I would be interested to know how others use lpeg.
> One strategy is to try and get the bare pattern right
> first, without using captures (if none are needed later
> in the matching process), and then to retro-fit the captures
> later. This I find quite tricky to get right, because one has
> to have a mental picture of the capture stack and how it gets
> manipulated.
> Does anyone have any informal advice or useful tips?
>
Know your grammar first, then write the PEG. Unlike for regexes, I don't
think there's any viable substitute for spending time grasping the
conceptual structure of what you're trying to parse.
Regexes let you explore the lexical elements as you play around with the
expression, and that's partly because of the backtracking. The backtracking
let's you write something which almost works, and which you can
incrementally refine. PEGs are less user-friendly this way.