lua-users home
lua-l archive

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


On 2012-10-10 2:51 PM, "Stefano" <phd.st.p@gmail.com> wrote:
>
> I have been recently using RiciLake pre-processor:
>
> http://lua-users.org/wiki/SlightlyLessSimpleLuaPreprocessor
>
> Has anyone thought of extending (or already extended) it to have
> comment-like behavior for # instead of requiring lines to start with
> #?
>
> Example:
>
> local x = 1.0 # <text for preprocessor here>
>
> #[===[
> <text for preprocessor here>
> ]===]
>
> The first one may not seem immediately useful but it allows cases like
> # preceded by a space (happens when the pre-processed text uses the
> preprocessor as well).
>
>
> Thanks
>
> Stefano
>

You'd have to change # to something that isn't already an operator in Lua. Even requiring lines to start with it isn't foolproof, since a line like "#t" is valid Lua code, and with metamethods, might even do something. (Think of alternate syntaxes like LPEG)

Allowing it to be anywhere in a line raises new issues too:
print ("Beginning test #1") --Uhoh, the preprocessor needs to know about strings now
--commented #foo. If it expands to multiple lines, we got a problem.

(and when you consider multi-line strings, again this can happen even at the beginning of a line)

I usually use @ as a marker for any preprocessing I do, since few languages use it for anything, which also helps it stand out.