需要帮助来了解LPeg和PEGs

Dec*_*ula 7 lua peg lpeg

以下模式(来自此页面)仅匹配具有平衡括号的字符串:

b = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" }
Run Code Online (Sandbox Code Playgroud)

是什么1-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
Run Code Online (Sandbox Code Playgroud)

什么是+1patt / repl + 1意味着什么?

而且我还没有/本文中很好地得到优先选择算子的功能

任何帮助将不胜感激!

Ada*_*dam 5

11 - lpeg.S"()"指任何字符.整个语句可以读作,匹配任何字符,而不匹配集合中的字符"()".

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