lua-users home
lua-l archive

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


Peace,

I was looking for a way to add new keywords to Lua without damage
previous written code. I found the following solutions:

1) A soft keyword that can be used as an identifier in all places
where identifiers are accepted. Soft keywords are not hidden by
variables of the same name (they occur in the grammar at places where
no identifier is allowed).

2) An weak keyword can be shadowed by an identifier. Weak keywords are
treated as keywords if (1) the grammar expects the keyword and (2)
there is no variable of the same name in scope.

"http://code.google.com/p/jaql/issues/detail?id=50";

The solution (1) seems useless due Lua syntax and the solution (2)
seems to be too loose, with identifiers having priority over keywords,
which is almost the opposite behavior I desired and also can cause a
kind of  "uncertainty" while you read the code, because the their
meaning could change along the text.

Probably must exist best solutions - after all - I am far from being a
specialist.

As I would like to antecipate the release of OOBit patch beta (90%
ready) using "method" as a kind of keyword, I would like to try a
different approach, temporarily named as "flex keywords" or
"flexwords".

The concept is quite simple:

When Lua parses a chunk (or module), the first time it found a
"flexword" will define the way that it will be used in ** that **
chunk (or module), as a ident or as a keyword. Trying to change the
mode inside the chunk generate an error.

Perhaps this could helps a lot with handling of legacy code without
too much damage in readability. Suppose that a new version of Lua use
"new" as keyword. In traditional way, any previous code (tons of code)
that used "new" as ident will need to be fix. With the "flexwords" no
code revision will be needed,.

Of course, I'm assuming that once a version of Lua makes "new" a
"flexword", the programmers will stop to use it as ident. If they
don't, the readability advantage in using "flexword" instead of strong
and weak keywords will be lost.

As usual, the implementation in Lua also seems to be quite viable.

I don't know if this approach already exists (I'm not a specialist),
but as it seems to help, I decided to ask for comments about it.

Well, any information about alternatives solutions or any other
suggestion is welcome.

Thank you for your attention,

Nilson