lua-users home
lua-l archive

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

On Jul 24, 2023, at 12:57 AM, Kartik Agaram <> wrote:
I've been thinking about the problem of stripping comments (including long/block comments) from a string containing Lua code. Is there some way to do this that is shorter than an imperative byte-by-byte state machine? I've considered Lua's patterns and also the Lpeg library, but without success.

There is a minimal but general lexical scanner built in to my Luke tool that I use with a short wrapper to minimize the size of the shipped luke sources.  It has no hard dependencies and strips comments (as well as extraneous whitespace and renames symbols to be shorter).  You’re welcome to take that and simplify it by removing the parts you don’t need.

If you don’t care about portability to luajit and 5.1+, then you could remove the std.normalize dependency being careful to check the semantics of the calls it shims match the version of Lua you’re targeting..