lua-users home
lua-l archive

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


Peter Hill:
> prefixexp ::= var | functioncall | '(' exp ')'
>
> But, at a glance, I can't see why one could not just include "function" in
> there as well.

Eero Pajarre:
> I hope we agree that feature requests are for Lua 5.1 or some latter
> version. For 5.0 I wish only bug fixes, and something which works as
> documented is by definition not a bug ;-) , and most of the rest can be
> fixed by changing the documentation ;-)

Waiting for Lua 5.1 is certainly fine by me... Lua 5.0 being a "beta".

And the change is not exactly earth-shattering. Rather, it is merely a fine
tuning of the syntax... ironing out quirky irregularities... aiming for a
more homogenous, regular & simple syntax [ie, easily understood].

Lua is so close to being fully regular (Lua 5.0 made some good changes in
this direction). Elegant simplicity... to delight the professionals & to
comfort the novices. A lofty goal. :-)

As far as homogenising changes go, I'd move all atomic items (not just
"function") out of "exp" and into "prefixexp" where they belong. Why, you
ask? "123()" hardly seems meaningful, let's just outlaw it and we don't have
to worry about numbers acting as functions. However, since Lua is not
statically typed, since "a()" is syntactically valid, and since "a" can be a
number (or literal string, or function closure, or nil / true / false) then
such a contruct is indeed valid up to evaluation time (and is potentially
trapped). So why generate two different errors for the same action?

So we get:
  <atom> ::= nil | false | true | {name} | {number} | {literal} | <function>
    | <table constructor> | "(" <exp> ")"

Note that "atoms" are fully syntactically wrapped. Ie, they are either a
single lexical item or are braced both left and right.

  <explist> ::= [{<exp> ","} <exp>]

  <args> ::= "(" <explist> ")" | <table constructor> | {literal}

  <prefixexp> ::= <atom>
    | <prefixexp> "[" <exp> "]"
    | <prefixexp> "." {name}
    | <prefixexp> <args>
    | <prefixexp> ":" {name} <args>

  <exp> ::= <prefixexp> | <unop> <exp> | <exp> <binop> <exp>


*cheers*
Peter Hill.