[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LPEG error location display
- From: Miles Bader <miles@...>
- Date: Sun, 12 Oct 2008 23:26:50 +0900
Florian Weimer <email@example.com> writes:
> I hit the same problem when using LPeg. Have you found a solution in
> the meantime?
I use a function matcher that records the current position, e.g.:
local function update_err_pos (text, pos)
parse_state.err_pos = pos
-- This special lpeg pattern updates the current error position
ERR_POS = P(update_err_pos)
[where "parse_state" is some global; probably better ways to do that
now, e.g., the special capture you can use to access the Nth arg of the
lpeg match call]
Then I stick ERR_POS in various places, for instance, after the
end-of-line pattern... e.g.:
-- this matches a newline, and also updates the error location
local WS_NL_SYNC = WS_NL * lu.ERR_POS
The error reporting routines then use the error position to find the
last line that was ever matched, and include that information along with
the error message.
Dawn, n. When men of reason go to bed.