[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LPEG error location display
- From: Miles Bader <miles@...>
- Date: Sun, 12 Oct 2008 23:26:50 +0900
Florian Weimer <fw@deneb.enyo.de> 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
return pos
end
-- 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.
-Miles
--
Dawn, n. When men of reason go to bed.