[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: stripping comments
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 24 Jul 2023 10:29:15 -0300
> 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.
I'ts certainly doable with LPeg, and it should not be too complicated.
The LPeg documentation already has an example of how to match long
strings. The tool also needs to match regular strings (to avoid removing
"comments" that appear inside strings), handling the escapes, but again
that is not that hard.
-- Roberto