lua-users home
lua-l archive

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


Some changes might be made in the Lua source to reduce the complexity
of patches and the likelihood of conflicts between patches.

Consider the "continue" patch [1], which extends the lexer like this:

-------------------------
 const char *const luaX_tokens [] = {
-    "and", "break", "do", "else", "elseif",
+    "and", "break", "continue", "do", "else", "elseif",
     "end", "false", "for", "function", "if",
---
#define FIRST_RESERVED	257
---
 enum RESERVED {
   /* terminal symbols denoted by reserved words */
-  TK_AND = FIRST_RESERVED, TK_BREAK,
+  TK_AND = FIRST_RESERVED, TK_BREAK, TK_CONTINUE,
   TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
-------------------------

That will conflict with other patches that extend the lexer with
nearby keywords.  I'd suggest the lexer being written like this:

----------------------------
static const char *const luaX_tokens [] = {
    /* terminal symbols denoted by reserved words */
    "and",
    "break",
    "do",
    "else",
    .....
---------------------------
enum RESERVED {
  /* terminal symbols denoted by reserved words */
  TK_RESERVED_BEFORE = FIRST_RESERVED - 1,
  TK_AND,
  TK_BREAK,
  TK_DO,
  .....
  TK_WHILE,
  TK_RESERVED_AFTER,
  /* other terminal symbols */
  TK_OTHER_BEFORE = TK_RESERVED_AFTER - 1,
  TK_CONCAT
  .....
/* number of reserved words */
#define NUM_RESERVED	(cast(int, TK_RESERVED_AFTER - TK_RESERVED_BEFORE - 1))
---------------------------

Similar things might be done elsewhere, such as adding a placeholder
after VINDEXED in expkind to avoid the hardcoded comparison here,
which will break if another variable kind is added after VINDEXED:

  #define vkisvar(k)	(VLOCAL <= (k) && (k) <= VINDEXED)

One may also write a Lua script that validates constraints like
"ORDERED RESERVED" on patched Lua sources.

[1] http://lua-users.org/wiki/LuaPowerPatches