lua-users home
lua-l archive

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


-- Pierre-Yves


On Wed, May 22, 2013 at 10:11 PM, Sean Conner <sean@conman.org> wrote:
> pattern = Cf(
>         Cc""
>         * (P"ao" / "a" + P"ii" / "i" + P"ue" / "u" + C(P(1)))^1,
>         function(a,b) return a .. b end
> )

Better still, assuming you want specific pairs to be simplified:

    setmetatable(_G,{__index = require"lpeg"}) -- ideal for REPL sessions.

    pattern = Cs(( P"ao" / "a" + P"ii" / "i" + P"ue" / "u" + 1 )^0)

    print(pattern:match"--ao--ii--ue--") --> --a--i--u--

You could also build the pattern iteratively:

    X = P(false)
    for k,v in pairs{ ao="a", ii = "i" } do X = X + P(k)/v end
    pattern = Cs(( X + 1 )^0)

For the generic case:

    v = S"aeiouy"
    pattern = Cs(( ( C(v) * v ) / 1 + 1 )^0)

But it seems that Petite Abeille is reluctant to use LPeg...
@P. A.: What don't you like about it?

-- Pierre-Yves