From 7d43b367e7a89369c1302124677a305aa0d070c7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 22 Jun 2023 10:51:31 -0300 Subject: Improved documentation for accumulator captures --- re.html | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 're.html') diff --git a/re.html b/re.html index ed4ccb1..114d968 100644 --- a/re.html +++ b/re.html @@ -61,6 +61,20 @@ Constructions are listed in order of decreasing precedence. + + + + + + + + + + + + + + @@ -69,22 +83,15 @@ Constructions are listed in order of decreasing precedence. + - - - - - - - - - + + @@ -94,11 +101,8 @@ equivalent to p / defs[name] equivalent to lpeg.Cmt(p, defs[name]) - - - - - +
SyntaxDescription
( p ) grouping
& p and predicate
! p not predicate
p1 p2 concatenation
p1 / p2 ordered choice
p ? optional match
p * zero or more repetitions
p + one or more repetitions
p^numexactly num repetitions
p^+numat least num repetitions
p^-numat most num repetitions
(name <- p)+ grammar
'string' literal string
"string" literal string
[class] character class
pattern defs[name] or a pre-defined pattern
namenon terminal
<name>non terminal
{} position capture
{ p } simple capture
{: p :} anonymous group capture
{:name: p :} named group capture
{~ p ~} substitution capture
{| p |} table capture
=name back reference -
p ? optional match
p * zero or more repetitions
p + one or more repetitions
p^num exactly n repetitions
p^+numat least n repetitions
p^-numat most n repetitions
=name back reference
p -> 'string' string capture
p -> "string" string capture
p -> num numbered capture
p ~> name fold capture equivalent to lpeg.Cf(p, defs[name])
& p and predicate
! p not predicate
p1 p2 concatenation
p1 / p2 ordered choice
(name <- p)+ grammar
p >> name accumulator capture +equivalent to (p % defs[name])

Any space appearing in a syntax description can be @@ -199,9 +203,10 @@ print(re.match("the number 423 is odd", "({%a+} / .)*")) --> the number is odd -- returns the first numeral in a string -print(re.match("the number 423 is odd", "s <- {%d+} / . s")) +print(re.match("the number 423 is odd", "s <- {%d+} / . s")) --> 423 +-- substitutes a dot for each vowel in a string print(re.gsub("hello World", "[aeiou]", ".")) --> h.ll. W.rld @@ -415,6 +420,7 @@ prefix <- '&' S prefix / '!' S prefix / suffix suffix <- primary S (([+*?] / '^' [+-]? num / '->' S (string / '{}' / name) + / '>>' S name / '=>' S name) S)* primary <- '(' exp ')' / string / class / defined -- cgit v1.2.3-55-g6feb