lua-users home
lua-l archive

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


> To get line numbers with lpeg I just make a backcapture to count the
> line number, and a pattern for line ending:


Another approach is to use a match-time capture on a pattern that only
gets triggered when there's a parsing error and then use the character
index that's passed in to calculate the line number.  Since there's a
possibility of line-spanning tokens like with multi-line strings or
comments, seems this might be a more robust technique.  Also it saves
the cost of counting line numbers (which is admittedly trivial) until
there's actually a need.

wes