lua-users home
lua-l archive

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


On Mon, Jun 15, 2015 at 5:37 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
Why would someone need '%m'? 

Really, I'm not sure they would need it very often.
 
The motivation presented here was to
escape the magic characters. But Lua ensures that it is safe to escape
any non-alphanumeric character, not only the magic ones. So, you can
escape anything that matches '%p' to have a valid, non-escaped pattern:

   p = string.gsub(p, "%p", "%%%0")

No need for '%m'.

Well if we look at the original email, voidptr69 gives the following example:

    s = "bla = bla(a[1]);"
    for ss in s:gmatch("(%m)") do
       print(ss)
    end

With the proposed '%m' semantics, this would print the opening and closing parentheses and square brackets, but not the letters, the equal sign, the spaces, or the semicolon. So, neither '%W' nor '%p' would give identical results. It seems likely that most of the time, '%p' is actually what someone *would* want in a situation like this. It's just not equivalent to the proposed functionality is all I'm pointing out.

-- 
Brigham Toskin