lua-users home
lua-l archive

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


2012/3/10 steve donovan <steve.j.donovan@gmail.com>:
> There are limitations - this is smart substitution but it is still on
> the lexical level. I cannot implement the most commonly suggested |x|
> 2*x syntax for short lambdas because it's hard to know where the
> expression ends without parsing it.  Some of the freedom of
> token-filtering is also lost, so I can't show you a filter that
> replaces newlines in tables with commas (I'm thinking of an elegant
> yet efficient way of doing this)
>
Maybe add a parser based lpeg lexer will solve this issue, like this:

macro.define("|", function(get)
  local names = get:names "|"
  local expr = macro.parser.expr(get)
  -- do what you want, maybe:
  return "function("..names..") return "..macro.parser.dump(expr).."end"
end)

this will enable the full power of metalua.