lua-users home
lua-l archive

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


On 18 August 2018 at 13:13, Sean Conner <sean@conman.org> wrote:
>   I made the following changes:
>
> diff --git a/url/url.lua b/url/url.lua
> index 821a9ac..09b90ba 100644
> --- a/url/url.lua
> +++ b/url/url.lua
> @@ -72,8 +72,8 @@ path_abempty    <- {| {:root: %istrue :} ( '/' segment)* |}
>  path_absolute   <- {| {:root: %istrue :}   '/' (segment_nz ('/' segment)* )? |}
>  path_noscheme   <- {| segment_nz_nc ('/' segment)* |}
>  path_rootless   <- {| segment_nz    ('/' segment)* |}
> -path_empty      <- ! . {| |}
> -segment         <- ! . / {~ pchar+ ~}
> +path_empty      <- {| |}
> +segment         <- {~ pchar* ~}
>  segment_nz      <- {~ pchar+ ~}
>  segment_nz_nc   <- {~ (unreserved / pct_encoded / sub_delims / ';' / '@')+ ~}
>  pchar           <-  unreserved / pct_encoded / sub_delims / ':' / '@'
>
>   And I still get the same results:
>
> url  = require "org.conman.parsers.url.url"
> lpeg = require "lpeg"
>
> x = url * lpeg.Cp()
>
> _,b = x:match "/status"   print(b) -- 8, which is right
>                     --^ here is position 8
> _,b = x:match "/status/"  print(b) -- 9, which is right
>                      --^ here is position 9
> _,b = x:match "/status "  print(b) -- 8, which is right
>                     --^ here is position 8
> _,b = x:match "/status/ " print(b) -- 8, which is incorrect, shoule be 9
>                      --^ here is *WHERE* is should be
>                     --^ here is where it's returning

I don't. Are you sure you're running the updated code?

$ diff -wu <(curl
https://raw.githubusercontent.com/spc476/LPeg-Parsers/9fe3db4c0a52264f9e0e78200cc0f7dda0008f04/url/url.lua)
spc.lua
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5323  100  5323    0     0  19788      0 --:--:-- --:--:-- --:--:-- 19788
--- /dev/fd/63    2018-08-18 13:17:24.546157840 +1000
+++ spc.lua    2018-08-18 13:17:09.479722521 +1000
@@ -72,8 +72,8 @@
 path_absolute   <- {| {:root: %istrue :}   '/' (segment_nz ('/' segment)* )? |}
 path_noscheme   <- {| segment_nz_nc ('/' segment)* |}
 path_rootless   <- {| segment_nz    ('/' segment)* |}
-path_empty      <- ! . {| |}
-segment         <- ! . / {~ pchar+ ~}
+path_empty      <- {| |}
+segment         <- {~ pchar* ~}
 segment_nz      <- {~ pchar+ ~}
 segment_nz_nc   <- {~ (unreserved / pct_encoded / sub_delims / ';' / '@')+ ~}
 pchar           <-  unreserved / pct_encoded / sub_delims / ':' / '@'
@@ -130,4 +130,16 @@
   pct_encoded = pct_encoded,
 }

-return re.compile(G,R)
+local url= re.compile(G,R)
+
+x = url * lpeg.Cp()
+
+a,b = x:match "/status"   print(b)
+a,b = x:match "/status/"  print(b)
+a,b = x:match "/status "  print(b)
+a,b = x:match "/status/ " print(b)
+
+a,b = x:match "/status#a" print(b)
+a,b = x:match "/status/#a" print(b)
$ lua spc.lua
8
9
8
9
10
11