lua-users home
lua-l archive

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


Hi Paul,

On Fri, Jun 13, 2014 at 8:05 PM, Paul K <paul@zerobrane.com> wrote:
> 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.

Speaking with the experience of making this [1], I imagine supporting
syntax errors would involve something like:

stat = V "goodstat" + V "badstat";
goodstat = V "stat-from-old-grammar";
badstat = (P(1) * -V "stat")^1

You could add captures to mark nodes as unknown. Finally, supporting
incomplete nodes like while would involve a similar alternative for
the end keyword.

[1] https://github.com/batrick/lunadry/blob/master/lunadry.lua

-- 
Patrick Donnelly