[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Anaphora and token filters
- From: Fabien <fleutot+lua@...>
- Date: Tue, 9 Jan 2007 12:24:53 +0100
In metalua, that would be:
$ cat awhile.lua
--macro back-end:
function awhile_builder(x)
local expr, var, block = unpack(x)
var = var or +{it}
return +{ stat: do
local -{var}
while true do
(-{var}) = -{expr}
if -{var} then -{block} else break end
end
end }
end
mlp.lexer.register "awhile" -- register the new keyword
--syntactical front-end:
mlp.stat.add{ builder = awhile_builder,
"awhile",
mlp.expr, gg.onkeyword{ ",", mlp.id, consume=true },
"do", mlp.block, "end" }
And here is a simplistic test program:
$ cat awhile_test.lua
-{ dofile "awhile.luac" }
x=0
awhile x do
print(it)
if x==10 then x=false else x=x+1 end
end
$ mlc awhile.lua
$ mlc -x awhile_test.lua