[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Proposal] Lua-y lambda syntax
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sun, 30 Apr 2017 12:45:24 -0300
The token filter below can be used with my ltokenp to convert
fct = λ (a,b,c) â?? 10*(10*a+b)+c â?ª
to
fct = function ( a , b , c ) return 10 * ( 10 * a + b ) + c end
-- token filter: handle utf symbols as keywords
local function emit(x)
io.write(x," ")
end
local acc=""
local convert={
["\xce\xbb"] = "function",
["\xe2\x86\x92"] = "return",
["\xe2\x96\xaa"] = "end",
}
local function flush()
if acc~="" then
emit(convert[acc])
acc=""
end
end
function FILTER(line,token,text,value)
local t=text
if t=="<file>" or t=="<eof>" then flush() return end
if t=="<string>" then value=string.format("%q",value) end
if token>127 and text==value then
acc=acc..t
else
flush()
emit(value)
end
end