lua-users home
lua-l archive

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


Hi All,

I'm looking for an LPeg-based parser that can handle partial content
or invalid syntax and still continue processing. I've looked at the
code of several LPeg-based parsers (many of them referenced in this
thread: http://lua-users.org/lists/lua-l/2013-09/msg00109.html), but
none of them seems to be able to continue processing after
encountering invalid syntax. For example,

n = 5
while n > 1 do
   print(n)
   n := n-1 --<-- syntax error
end
print(n)

I'd like to be able to build AST and mark the "unknown" node as
"unknown" and continue processing. I'd also like to be able to handle
incomplete fragments:

n = 5
while n > 1 do
   print(n)
   n

This would generate a node for "while" and mark it as "incomplete" as
there is no corresponding "end" to close that statement.

I've been using David Manura's loose parser
(https://github.com/davidm/lua-parser-loose), which does something
like this, but I'm interested in LPeg-based solution.

Does anyone have an example of how this can be done with LPeg? Thank you.

Paul.