lua-users home
lua-l archive

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


On Sun, Jul 25, 2010 at 6:18 AM, Peter Cawley <lua@corsix.org> wrote:
> On Sun, Jul 25, 2010 at 1:13 AM, David Manura <dm.lua@math2.org> wrote:
>> ...but a difficulty is that Lua currently doesn't
>> include column numbers in parser error messages (which at times I've
>> thought it should--like it would be of some use to me in LuaInspect).
>
> For this particular case, perhaps you could use a custom lua_Reader
> which feeds in the chunk one byte at a time, and keeps track of how
> many bytes have been requested. For large inputs, this might be
> inefficient, but a combination of feeding one byte at a time and
> binary search should fix that.

That looks like a good idea.  The first pass of loadstring gives you a
line number.  Then you can call `load` with a chunk reader, passing
each byte or even each token or approximation of a token (e.g.
'%w*%W+') on the line individually.