[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: There's a bug in my LPeg code, but I can't find it
- From: Albert Chan <albertmcchan@...>
- Date: Fri, 17 Aug 2018 22:31:17 -0400
On Aug 17, 2018, at 8:33 PM, Sean Conner <sean@conman.org> wrote:
> The following code presents the bug:
>
> url = require "org.conman.parsers.url.url"
> lpeg = require "lpeg"
>
> x = url * lpeg.Cp()
>
> a,b = x:match "/status" print(b) -- prints 8, okay
> a,b = x:match "/status/" print(b) -- prints 9, okay
> a,b = x:match "/status " print(b) -- prints 8, okay
> a,b = x:match "/status/ " print(b) -- prints 8, WAT?
Hi, Sean
Is the expected result 9 ? 10 ?
i do not know how url work, but can segment add space as alternative ?
Or space lookahead (so capture position stay at 9) ?
> The 'segment' rule *should* be
>
> segment <- ! . / {~ pchar* ~}
does above removed end-of-line test ? It seems match everything.
if that is what you want, it seems working:
lua> =re.match("/status/ ", [[ '/' [a-z]+ ('/' [a-z]*)* {} ]])
9