lua-users home
lua-l archive

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


```lua


local lpeg = require'lpeg'
local C = lpeg.C
local P = lpeg.P
local Cg = lpeg.Cg


local find = function(str)
    return (P(1) - str)^0 * C(str)
end

local cg_test =  Cg(find("string") * find("cool"))

local test = "my string is not cool."

print(cg_test:match(test))
--> string\tcool

print(select("#", cg_test:match(test)))
--> 2

--Same as...
print((find("string") * find("cool")):match(test))
--> string\tcool

print(select("#", (find("string") * find("cool")):match(test)))
--> 2

```

I'm expecting...

```lua

print(cg_test:match(test))
--> stringcool
print(select("#", cg_test:match(test)))
--> 1
```

...because the manual[1] says:

     An anonymous group serves to join values from several captures
into a single capture.



What am I missing?

--Andrew

[1]: http://www.inf.puc-rio.br/~roberto/lpeg/#cap-g