luapack/plug/arrow.lua
2022-05-04 04:48:42 +03:00

17 lines
394 B
Lua

-- Arrow functions in Lua
-- f = (n) => 2 + n
return function(op)
return {
name = 'Arrow functions',
transform = function(e, opts)
return e.src
-- multiple-line
:gsub('%(([^%(%)]*)%)%s*==>%s*(.-)%s<==',
'function(%1) %2 end')
-- single-line
:gsub('%(([^%(%)]*)%)%s*=>[ \t\v\f]*([^\n\r]*)',
'function(%1) return %2 end')
end,
}
end