aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-17 16:25:25 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-17 16:25:25 -0300
commit80ec9f932aa01d445e86c699523265359055e1bd (patch)
treec32ee93fba8e2af7c114ee177b7fe2c8e353650a
parent73a96935337d78d0e1015d7ccce6cf7470c192c4 (diff)
downloadlpeg-master.tar.gz
lpeg-master.tar.bz2
lpeg-master.zip
Small improvementsHEADmaster
-rw-r--r--lpeg.html30
-rw-r--r--lptree.c2
-rw-r--r--lptypes.h1
-rw-r--r--makefile1
-rwxr-xr-xtest.lua2
5 files changed, 25 insertions, 11 deletions
diff --git a/lpeg.html b/lpeg.html
index b31d575..bd54294 100644
--- a/lpeg.html
+++ b/lpeg.html
@@ -53,19 +53,22 @@
53<h2><a name="intro">Introduction</a></h2> 53<h2><a name="intro">Introduction</a></h2>
54 54
55<p> 55<p>
56<em>LPeg</em> is a new pattern-matching library for Lua, 56<em>LPeg</em> is a pattern-matching library for Lua,
57based on 57based on
58<a href="//bford.info/packrat/"> 58<a href="//bford.info/packrat/">
59Parsing Expression Grammars</a> (PEGs). 59Parsing Expression Grammars</a> (PEGs).
60This text is a reference manual for the library. 60This text is a reference manual for the library.
61For those starting with LPeg,
62<a href="https://www.inf.puc-rio.br/~roberto/docs/lpeg-primer.pdf">
63Mastering LPeg</a> presents a good tutorial.
61For a more formal treatment of LPeg, 64For a more formal treatment of LPeg,
62as well as some discussion about its implementation, 65as well as some discussion about its implementation,
63see 66see
64<a href="//www.inf.puc-rio.br/~roberto/docs/peg.pdf"> 67<a href="//www.inf.puc-rio.br/~roberto/docs/peg.pdf">
65A Text Pattern-Matching Tool based on Parsing Expression Grammars</a>. 68A Text Pattern-Matching Tool based on Parsing Expression Grammars</a>.
66(You may also be interested in my 69You may also be interested in my
67<a href="//vimeo.com/1485123">talk about LPeg</a> 70<a href="//vimeo.com/1485123">talk about LPeg</a>
68given at the III Lua Workshop.) 71given at the III Lua Workshop.
69</p> 72</p>
70 73
71<p> 74<p>
@@ -664,13 +667,22 @@ produces values for each match.
664 667
665<p> 668<p>
666Usually, 669Usually,
667LPeg does not specify when (and if) it evaluates its captures. 670LPeg does not specify when, if, or how many times it evaluates its captures.
668(As an example,
669consider the pattern <code>lpeg.P"a" / func / 0</code>.
670Because the "division" by 0 instructs LPeg to throw away the
671results from the pattern,
672it is not specified whether LPeg will call <code>func</code>.)
673Therefore, captures should avoid side effects. 671Therefore, captures should avoid side effects.
672As an example,
673LPeg may or may not call <code>func</code> in the pattern
674<code>lpeg.P"a" / func / 0</code>,
675given that the <a href="#cap-num">"division" by 0</a>
676instructs LPeg to throw away the
677results from the pattern.
678Similarly, a capture nested inside a <a href="#cap-g">named group</a>
679may be evaluated only when that group is referred in a
680<a href="#cap-b">back capture</a>;
681if there are multiple back captures,
682the group may be evaluated multiple times.
683</p>
684
685<p>
674Moreover, 686Moreover,
675captures cannot affect the way a pattern matches a subject. 687captures cannot affect the way a pattern matches a subject.
676The only exception to this rule is the 688The only exception to this rule is the
diff --git a/lptree.c b/lptree.c
index 475b0c3..a176ad9 100644
--- a/lptree.c
+++ b/lptree.c
@@ -1123,7 +1123,7 @@ static int verifyrule (lua_State *L, TTree *tree, unsigned short *passed,
1123 return verifyerror(L, passed, npassed); /* error */ 1123 return verifyerror(L, passed, npassed); /* error */
1124 else { 1124 else {
1125 passed[npassed++] = tree->key; /* add rule to path */ 1125 passed[npassed++] = tree->key; /* add rule to path */
1126 /* return verifyrule(L, sib1(tree), passed, npassed); */ 1126 /* return verifyrule(L, sib1(tree), passed, npassed, nb); */
1127 tree = sib1(tree); goto tailcall; 1127 tree = sib1(tree); goto tailcall;
1128 } 1128 }
1129 case TGrammar: 1129 case TGrammar:
diff --git a/lptypes.h b/lptypes.h
index 3f860b9..b5cea44 100644
--- a/lptypes.h
+++ b/lptypes.h
@@ -34,6 +34,7 @@
34 34
35#define lua_rawlen lua_objlen 35#define lua_rawlen lua_objlen
36 36
37#undef luaL_newlib
37#define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f) 38#define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f)
38#define luaL_newlib(L,f) luaL_register(L,"lpeg",f) 39#define luaL_newlib(L,f) luaL_register(L,"lpeg",f)
39 40
diff --git a/makefile b/makefile
index 41a2928..82a95bb 100644
--- a/makefile
+++ b/makefile
@@ -1,5 +1,6 @@
1LIBNAME = lpeg 1LIBNAME = lpeg
2LUADIR = ./lua/ 2LUADIR = ./lua/
3#LUADIR = /home/roberto/prj/lua/
3 4
4COPT = -O2 -DNDEBUG 5COPT = -O2 -DNDEBUG
5# COPT = -O0 -DLPEG_DEBUG -g 6# COPT = -O0 -DLPEG_DEBUG -g
diff --git a/test.lua b/test.lua
index d0b82da..3241408 100755
--- a/test.lua
+++ b/test.lua
@@ -47,7 +47,7 @@ end
47print"General tests for LPeg library" 47print"General tests for LPeg library"
48 48
49assert(type(m.version) == "string") 49assert(type(m.version) == "string")
50print(m.version) 50print(m.version, _VERSION)
51assert(m.type("alo") ~= "pattern") 51assert(m.type("alo") ~= "pattern")
52assert(m.type(io.input) ~= "pattern") 52assert(m.type(io.input) ~= "pattern")
53assert(m.type(m.P"alo") == "pattern") 53assert(m.type(m.P"alo") == "pattern")