[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: folding double vowels?
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Wed, 22 May 2013 22:41:16 +0200
-- 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