[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: parser : which library ?
- From: Wesley Smith <wesley.hoke@...>
- Date: Mon, 30 May 2011 17:27:28 -0700
> 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  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  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.