The following pattern (from this page) matches only strings with balanced parentheses:
b = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" }
What does 1-
in 1 - lpeg.S"()"
mean?
function gsub (s, patt, repl)
patt = lpeg.P(patt)
patt = lpeg.Cs((patt / repl + 1)^0)
return lpeg.match(patt, s)
end
What does the +1
in patt / repl + 1
mean?
And I still not quite get the function of prioritized choice operator /
very well from this paper
Any help will be appreciated!