lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.