Need help understanding LPEG and PEGs

The following pattern (from this page ) only matches strings with balanced parentheses:

b = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" } 

What does 1- in 1 - lpeg.S"()" mean 1 - lpeg.S"()" ?

 function gsub (s, patt, repl) patt = lpeg.P(patt) patt = lpeg.Cs((patt / repl + 1)^0) return lpeg.match(patt, s) end 

What does +1 in patt / repl + 1 mean?

And so far I have not used the function of the priority operator of choice / from this article very well

Any help would be appreciated!

+7
lua peg lpeg
source share
1 answer

1 in 1 - lpeg.S"()" means any character. The entire operator can be read as, match any character that does not match the character in the set "()" .

+1 is the same idea, if repl is a string, then patt / repl + 1 matches the patt pattern, and then replaces it with a capture on the repl string or skips the character.

+4
source share

All Articles