From 80ec9f932aa01d445e86c699523265359055e1bd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 17 Jun 2024 16:25:25 -0300 Subject: Small improvements --- lpeg.html | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'lpeg.html') diff --git a/lpeg.html b/lpeg.html index b31d575..bd54294 100644 --- a/lpeg.html +++ b/lpeg.html @@ -53,19 +53,22 @@

Introduction

-LPeg is a new pattern-matching library for Lua, +LPeg is a pattern-matching library for Lua, based on Parsing Expression Grammars (PEGs). This text is a reference manual for the library. +For those starting with LPeg, + +Mastering LPeg presents a good tutorial. For a more formal treatment of LPeg, as well as some discussion about its implementation, see A Text Pattern-Matching Tool based on Parsing Expression Grammars. -(You may also be interested in my +You may also be interested in my talk about LPeg -given at the III Lua Workshop.) +given at the III Lua Workshop.

@@ -664,13 +667,22 @@ produces values for each match.

Usually, -LPeg does not specify when (and if) it evaluates its captures. -(As an example, -consider the pattern lpeg.P"a" / func / 0. -Because the "division" by 0 instructs LPeg to throw away the -results from the pattern, -it is not specified whether LPeg will call func.) +LPeg does not specify when, if, or how many times it evaluates its captures. Therefore, captures should avoid side effects. +As an example, +LPeg may or may not call func in the pattern +lpeg.P"a" / func / 0, +given that the "division" by 0 +instructs LPeg to throw away the +results from the pattern. +Similarly, a capture nested inside a named group +may be evaluated only when that group is referred in a +back capture; +if there are multiple back captures, +the group may be evaluated multiple times. +

+ +

Moreover, captures cannot affect the way a pattern matches a subject. The only exception to this rule is the -- cgit v1.2.3-55-g6feb