[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LPeg back captures
- From: Andrew Starks <andrew.starks@...>
- Date: Wed, 23 Oct 2013 22:55:15 -0500
On Wed, Oct 23, 2013 at 10:10 PM, Sean Conner <sean@conman.org> wrote:
>> > DIGIT = R"09"
>> > delim_char = P"!" -- Cb("delim")
>> > flags = P"i"
>> > backref = P"\\" * DIGIT
>> > escapeddelim = P"\\" * delim_char
>> > anychar = P(1) - delim_char
>> > string = (escapeddelim + anychar)^1
>> > repl = C((string + backref)^0)
>> > ere = C((P(1) - delim_char)^0)
>> > idelim_char = Cg(P"/" + P"!" + (P(1) - (DIGIT + flags)),"delim")
>> > regexp = Ct(
>> > idelim_char
>> > * Cg(ere,"re")
>> > * delim_char
>> > * Cg(repl,"replace")
>> > * delim_char
>> > * Cg(flags^0,"flags")
>> > )
Man... I'm sorry. I thought I was pretty sure on this. I did some
tests on a simpler example and I was wrong again. Order of declaration
doesn't matter....
```
lpeg = require'lpeg'
P, Cg, Cb, C = lpeg.P, lpeg.Cg, lpeg.Cb, lpeg.C
the_forb_back_there = Cb("forb")
forb_cap = Cg(P(P"foo" + "bar"), "forb")
main_patt = C(forb_cap * (P(1))^1 * the_forb_back_there)
print(main_patt:match("barnillydissle"))
-->barnillydissle bar
```
bar is coming out as a separate return value.... I think that may be
the problem. I'm gonna dig more.