lua-users home
lua-l archive

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


> LPEG is brilliant for small parsing tasks. Its main weakness is that it doesn't provide much help for error reporting and recovery. If the context of the code ensures that you don't have syntax errors, e.g. machine-generated strings or other tools to check for errors, then LPEG can get you a long way.

I definitely agree with this.  The temptation with LPEG is to build an
all-in-one lexer/parser since LPEG only deals with strings.  I would
highly recommend using lpeglist [1] for writing parsers because you
can divide the lexer and parser into two steps as it should be where
the lexer generates an array of tokens and the parser runs over the
tokens to build the AST.

If you need something more sophisticated that can help with error
reporting and input validation, the codepeg [2] module I've written
around listlpeg provides mechanisms to help with that.  It's really
useful also simply for writing grammars because you can print out the
trace of rules and tokens the parser matches/attempts, making it easy
to spot bugs in the grammar itself.

wes

[1] https://github.com/mascarenhas/lpeg-list
[2] https://github.com/weshoke/codepeg/