[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LPeg and whitespace removal
- From: "Francisco Sant'anna" <francisco.santanna@...>
- Date: Thu, 12 Apr 2007 14:33:05 -0300
This one should work, don't know if it's elegant:
ws = lpeg.P'*'
sep = lpeg.P','
elem = ws^0 * lpeg.C((1 - (sep+ws))^0) * ws^0
p = elem * (sep * elem)^0
On 4/12/07, Joshua Jensen <firstname.lastname@example.org> wrote:
As my first attempt at using LPeg, I took the Splitting a String example
and wanted to extend it to filter out whitespace on either side of the
string. All whitespace (represented as a visible *) is removed from the
pattern below except the whitespace at the end. I understand why it
doesn't work; I don't understand how to make an elegant fix for it. I
tried all kinds of approaches without success.
ws = lpeg.P
sep = ws * lpeg.P(',') * ws
elem = (lpeg.C((1 - sep)^0))
p = ws * elem * (sep * elem)^0
Can anyone clue me in?