lua-users home
lua-l archive

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

Fabien wrote:
> Generally speaking, the most limiting feature of Lua syntax, when you
> want to extend/modify it, is the lack of mandatory statement separators.
> If you think of a random extension, 3/4 of the time it will introduce
> statement separation ambiguities, sometimes hard to suppress.

I have to agree with you here. It does make things awkward. Luckily for
me, @ isn't used for anything in Lua, so I can use @-prefixed keywords
for a clean namespace; it might be a useful extension for Lua 5.2 to
actually *define* a language extension namespace for this sort of thing,
like Java annotations.

> Since you're going to break source compatibility anyway, I'd suggest
> that you make the ";" statement separators mandatory.  Since your
> program's purpose is to clarify sources, I fear that introducing
> contrived rules to resolve parsing ambiguities would defeat its main
> purpose.

Believe me, I've thought about it! But it is, I think, a step too far
away from being a strict Lua superset for comfort. I've already had to
break compatibility in one area (see below)...

Introducing a new keyword for method declarations is probably the least
bad workaround.

> Note that mandatory separators would also solve your index/invocation
> ambiguity; here again, the other clean alternative would be to use
> another keyword than "[" to introduce invocations.

Actually, the ambiguity goes away if you do enough lookahead. An index
is always '[' expr ']'; and method call is always '[' expr selector
extended-selector ']', so I can simply test for the existence of the ']'
or not and backtrack if necessary. (A table-driven parser wouldn't need
to backtrack, but I'm using a recursive descent parser.)

In fact, I did find a syntax ambiguity.

Working: [o doSomething]
Working: [o doSomethingWith: [o doSomething]]
Failing: [[o doSomething] doSomething]

It took me *ages* to figure out why the third example gave weird parse
errors --- I'd completely forgotten about Lua's [[...]] long string
syntax! So I've had to disable that (I reckon that nested method calls
are more useful). Which means, alas, that OLua will not be a strict
superset of Lua, to my regret.

┌─── ───── ─────
│ ⍎'⎕',∊N⍴⊂S←'←⎕←(3=T)⋎M⋏2=T←⊃+/(V⌽"⊂M),(V⊝"M),(V,⌽V)⌽"(V,V←1⎺1)⊝"⊂M)'
│ --- Conway's Game Of Life, in one line of APL