diff options
-rw-r--r-- | README.md | 48 | ||||
-rw-r--r-- | examples/expRec.lua | 4 | ||||
-rw-r--r-- | examples/expRecAut.lua | 4 | ||||
-rw-r--r-- | examples/listId1.lua | 4 | ||||
-rw-r--r-- | examples/listId2.lua | 4 | ||||
-rw-r--r-- | examples/listId2Rec2.lua | 4 | ||||
-rw-r--r-- | examples/listId2Rec2Cap.lua | 4 | ||||
-rw-r--r-- | examples/listIdRe1.lua | 2 | ||||
-rw-r--r-- | examples/listIdRe2.lua | 2 | ||||
-rw-r--r-- | examples/tiny.lua | 2 | ||||
-rw-r--r-- | examples/typedlua/tllexer.lua | 2 | ||||
-rw-r--r-- | examples/typedlua/tlparser.lua | 2 | ||||
-rw-r--r-- | lptree.c | 4 | ||||
-rw-r--r-- | makefile | 14 | ||||
-rw-r--r-- | relabel.lua | 2 | ||||
-rwxr-xr-x | test.lua | 4 | ||||
-rw-r--r-- | testlabel.lua | 4 | ||||
-rw-r--r-- | testrelabelparser.lua | 2 |
18 files changed, 56 insertions, 56 deletions
@@ -35,21 +35,21 @@ Below there is a brief summary of the new functions provided by LpegLabel: | |||
35 | 35 | ||
36 | <table border="1"> | 36 | <table border="1"> |
37 | <tbody><tr><td><b>Function</b></td><td><b>Description</b></td></tr> | 37 | <tbody><tr><td><b>Function</b></td><td><b>Description</b></td></tr> |
38 | <tr><td><a href="#f-t"><code>lpeglabelrec.T (l)</code></a></td> | 38 | <tr><td><a href="#f-t"><code>lpeglabel.T (l)</code></a></td> |
39 | <td>Throws a label <code>l</code> to signal an error</td></tr> | 39 | <td>Throws a label <code>l</code> to signal an error</td></tr> |
40 | <tr><td><a href="#f-rec"><code>lpeglabelrec.Rec (p1, p2, l1 [, l2, ..., ln])</code></a></td> | 40 | <tr><td><a href="#f-rec"><code>lpeglabel.Rec (p1, p2, l1 [, l2, ..., ln])</code></a></td> |
41 | <td>Specifies a recovery pattern <code>p2</code> for <code>p1</code>, | 41 | <td>Specifies a recovery pattern <code>p2</code> for <code>p1</code>, |
42 | when the matching of <code>p1</code> gives one of the labels l1, ..., ln.</td></tr> | 42 | when the matching of <code>p1</code> gives one of the labels l1, ..., ln.</td></tr> |
43 | <tr><td><a href="#re-t"><code>%{l}</code></a></td> | 43 | <tr><td><a href="#re-t"><code>%{l}</code></a></td> |
44 | <td>Syntax of <em>relabelrec</em> module. Equivalent to <code>lpeglabelrec.T(l)</code> | 44 | <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeglabel.T(l)</code> |
45 | </td></tr> | 45 | </td></tr> |
46 | <tr><td><a href="#re-rec"><code>p1 //{l1 [, l2, ..., ln} p2</code></a></td> | 46 | <tr><td><a href="#re-rec"><code>p1 //{l1 [, l2, ..., ln} p2</code></a></td> |
47 | <td>Syntax of <em>relabelrec</em> module. Equivalent to <code>lpeglabelrec.Rec(p1, p2, l1, ..., ln)</code> | 47 | <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeglabel.Rec(p1, p2, l1, ..., ln)</code> |
48 | </td></tr> | 48 | </td></tr> |
49 | <tr><td><a href="#re-line"><code>relabelrec.calcline(subject, i)</code></a></td> | 49 | <tr><td><a href="#re-line"><code>relabel.calcline(subject, i)</code></a></td> |
50 | <td>Calculates line and column information regarding position <i>i</i> of the subject</code> | 50 | <td>Calculates line and column information regarding position <i>i</i> of the subject</code> |
51 | </td></tr> | 51 | </td></tr> |
52 | <tr><td><a href="#re-setl"><code>relabelrec.setlabels (tlabel)</code></a></td> | 52 | <tr><td><a href="#re-setl"><code>relabel.setlabels (tlabel)</code></a></td> |
53 | <td>Allows to specicify a table with mnemonic labels. | 53 | <td>Allows to specicify a table with mnemonic labels. |
54 | </td></tr> | 54 | </td></tr> |
55 | </tbody></table> | 55 | </tbody></table> |
@@ -58,14 +58,14 @@ Below there is a brief summary of the new functions provided by LpegLabel: | |||
58 | ### Functions | 58 | ### Functions |
59 | 59 | ||
60 | 60 | ||
61 | #### <a name="f-t"></a><code>lpeglabelrec.T(l)</code> | 61 | #### <a name="f-t"></a><code>lpeglabel.T(l)</code> |
62 | 62 | ||
63 | 63 | ||
64 | Returns a pattern that throws the label `l`. | 64 | Returns a pattern that throws the label `l`. |
65 | A label must be an integer between 1 and 255. | 65 | A label must be an integer between 1 and 255. |
66 | 66 | ||
67 | 67 | ||
68 | #### <a name="f-rec"></a><code>lpeglabelrec.Rec(p1, p2, l1, ..., ln)</code> | 68 | #### <a name="f-rec"></a><code>lpeglabel.Rec(p1, p2, l1, ..., ln)</code> |
69 | 69 | ||
70 | Returns a *recovery pattern*. | 70 | Returns a *recovery pattern*. |
71 | If the matching of `p1` gives one of the labels `l1, ..., ln`, | 71 | If the matching of `p1` gives one of the labels `l1, ..., ln`, |
@@ -76,23 +76,23 @@ Otherwise, the result of the matching of `p1` is the pattern's result. | |||
76 | 76 | ||
77 | #### <a name="re-t"></a><code>%{l}</code> | 77 | #### <a name="re-t"></a><code>%{l}</code> |
78 | 78 | ||
79 | Syntax of *relabelrec* module. Equivalent to `lpeg.T(l)`. | 79 | Syntax of *relabel* module. Equivalent to `lpeg.T(l)`. |
80 | 80 | ||
81 | 81 | ||
82 | #### <a name="re-lc"></a><code>p1 //{l1, ..., ln} p2</code> | 82 | #### <a name="re-lc"></a><code>p1 //{l1, ..., ln} p2</code> |
83 | 83 | ||
84 | Syntax of *relabelrec* module. Equivalent to `lpeglabelrec.Rec(p1, p2, l1, ..., ln)`. | 84 | Syntax of *relabel* module. Equivalent to `lpeglabel.Rec(p1, p2, l1, ..., ln)`. |
85 | 85 | ||
86 | The `//{}` operator is left-associative. | 86 | The `//{}` operator is left-associative. |
87 | 87 | ||
88 | 88 | ||
89 | 89 | ||
90 | #### <a name="re-line"></a><code>relabelrec.calcline (subject, i)</code> | 90 | #### <a name="re-line"></a><code>relabel.calcline (subject, i)</code> |
91 | 91 | ||
92 | Returns line and column information regarding position <i>i</i> of the subject. | 92 | Returns line and column information regarding position <i>i</i> of the subject. |
93 | 93 | ||
94 | 94 | ||
95 | #### <a name="re-setl"></a><code>relabelrec.setlabels (tlabel)</code> | 95 | #### <a name="re-setl"></a><code>relabel.setlabels (tlabel)</code> |
96 | 96 | ||
97 | Allows to specicify a table with labels. They keys of | 97 | Allows to specicify a table with labels. They keys of |
98 | `tlabel` must be integers between 1 and 255, | 98 | `tlabel` must be integers between 1 and 255, |
@@ -118,8 +118,8 @@ table and to return the index associated with each error message. | |||
118 | 118 | ||
119 | 119 | ||
120 | ```lua | 120 | ```lua |
121 | local m = require'lpeglabelrec' | 121 | local m = require'lpeglabel' |
122 | local re = require'relabelrec' | 122 | local re = require'relabel' |
123 | 123 | ||
124 | local terror = {} | 124 | local terror = {} |
125 | 125 | ||
@@ -176,7 +176,7 @@ the <em>regular</em> matching. For example, in the example below | |||
176 | we expect to match rule `A`, but when a failure occur the label 42 | 176 | we expect to match rule `A`, but when a failure occur the label 42 |
177 | is thrown and then we will try to match the recovery pattern `recp`: | 177 | is thrown and then we will try to match the recovery pattern `recp`: |
178 | ```lua | 178 | ```lua |
179 | local m = require'lpeglabelrec' | 179 | local m = require'lpeglabel' |
180 | 180 | ||
181 | local recp = m.P"oast" | 181 | local recp = m.P"oast" |
182 | 182 | ||
@@ -223,8 +223,8 @@ When the matching of an identifier fails, a defaul value ('NONE') | |||
223 | is provided. | 223 | is provided. |
224 | 224 | ||
225 | ```lua | 225 | ```lua |
226 | local m = require'lpeglabelrec' | 226 | local m = require'lpeglabel' |
227 | local re = require'relabelrec' | 227 | local re = require'relabel' |
228 | 228 | ||
229 | local terror = {} | 229 | local terror = {} |
230 | 230 | ||
@@ -311,14 +311,14 @@ print(mymatch(grec, "one\n two123, \nthree,")) | |||
311 | -- Error at line 3 (col 6): expecting an identifier | 311 | -- Error at line 3 (col 6): expecting an identifier |
312 | ``` | 312 | ``` |
313 | 313 | ||
314 | ##### *relabelrec* syntax | 314 | ##### *relabel* syntax |
315 | 315 | ||
316 | Below we describe again a grammar that matches a list of identifiers, | 316 | Below we describe again a grammar that matches a list of identifiers, |
317 | now using the syntax supported by *relabelrec*, where `//{}` is the | 317 | now using the syntax supported by *relabel*, where `//{}` is the |
318 | recovery operator, and `%{}` is the throw operator: | 318 | recovery operator, and `%{}` is the throw operator: |
319 | 319 | ||
320 | ```lua | 320 | ```lua |
321 | local re = require 'relabelrec' | 321 | local re = require 'relabel' |
322 | 322 | ||
323 | local errinfo = { | 323 | local errinfo = { |
324 | {"errUndef", "undefined"}, | 324 | {"errUndef", "undefined"}, |
@@ -428,8 +428,8 @@ task to build manually the recovery grammar `grec`. In the next example | |||
428 | we will show how to build the recovery grammar in a more automatic way. | 428 | we will show how to build the recovery grammar in a more automatic way. |
429 | 429 | ||
430 | ```lua | 430 | ```lua |
431 | local m = require"lpeglabelrec" | 431 | local m = require"lpeglabel" |
432 | local re = require"relabelrec" | 432 | local re = require"relabel" |
433 | 433 | ||
434 | local labels = { | 434 | local labels = { |
435 | {"ExpTermFirst", "expected an expression"}, | 435 | {"ExpTermFirst", "expected an expression"}, |
@@ -566,8 +566,8 @@ In the example below we also throw an error when the grammar | |||
566 | does not match the whole subject. | 566 | does not match the whole subject. |
567 | 567 | ||
568 | ```lua | 568 | ```lua |
569 | local m = require"lpeglabelrec" | 569 | local m = require"lpeglabel" |
570 | local re = require"relabelrec" | 570 | local re = require"relabel" |
571 | 571 | ||
572 | local num = m.R("09")^1 / tonumber | 572 | local num = m.R("09")^1 / tonumber |
573 | local op = m.S("+-") | 573 | local op = m.S("+-") |
diff --git a/examples/expRec.lua b/examples/expRec.lua index 5c5fd7d..52bd40a 100644 --- a/examples/expRec.lua +++ b/examples/expRec.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local m = require"lpeglabelrec" | 1 | local m = require"lpeglabel" |
2 | local re = require"relabelrec" | 2 | local re = require"relabel" |
3 | 3 | ||
4 | local labels = { | 4 | local labels = { |
5 | {"ExpTermFirst", "expected an expression"}, | 5 | {"ExpTermFirst", "expected an expression"}, |
diff --git a/examples/expRecAut.lua b/examples/expRecAut.lua index f870d73..b8280a7 100644 --- a/examples/expRecAut.lua +++ b/examples/expRecAut.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local m = require"lpeglabelrec" | 1 | local m = require"lpeglabel" |
2 | local re = require"relabelrec" | 2 | local re = require"relabel" |
3 | 3 | ||
4 | local num = m.R("09")^1 / tonumber | 4 | local num = m.R("09")^1 / tonumber |
5 | local op = m.S("+-") | 5 | local op = m.S("+-") |
diff --git a/examples/listId1.lua b/examples/listId1.lua index dee46e9..b7943c1 100644 --- a/examples/listId1.lua +++ b/examples/listId1.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local m = require'lpeglabelrec' | 1 | local m = require'lpeglabel' |
2 | local re = require'relabelrec' | 2 | local re = require'relabel' |
3 | 3 | ||
4 | local id = m.R'az'^1 | 4 | local id = m.R'az'^1 |
5 | 5 | ||
diff --git a/examples/listId2.lua b/examples/listId2.lua index 46f0063..3ee89da 100644 --- a/examples/listId2.lua +++ b/examples/listId2.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local m = require'lpeglabelrec' | 1 | local m = require'lpeglabel' |
2 | local re = require'relabelrec' | 2 | local re = require'relabel' |
3 | 3 | ||
4 | local terror = {} | 4 | local terror = {} |
5 | 5 | ||
diff --git a/examples/listId2Rec2.lua b/examples/listId2Rec2.lua index c6705dd..3506095 100644 --- a/examples/listId2Rec2.lua +++ b/examples/listId2Rec2.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local m = require'lpeglabelrec' | 1 | local m = require'lpeglabel' |
2 | local re = require'relabelrec' | 2 | local re = require'relabel' |
3 | 3 | ||
4 | local terror = {} | 4 | local terror = {} |
5 | 5 | ||
diff --git a/examples/listId2Rec2Cap.lua b/examples/listId2Rec2Cap.lua index 1c22c88..32a4113 100644 --- a/examples/listId2Rec2Cap.lua +++ b/examples/listId2Rec2Cap.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local m = require'lpeglabelrec' | 1 | local m = require'lpeglabel' |
2 | local re = require'relabelrec' | 2 | local re = require'relabel' |
3 | 3 | ||
4 | local terror = {} | 4 | local terror = {} |
5 | 5 | ||
diff --git a/examples/listIdRe1.lua b/examples/listIdRe1.lua index 3988a3b..3098c66 100644 --- a/examples/listIdRe1.lua +++ b/examples/listIdRe1.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local re = require 'relabelrec' | 1 | local re = require 'relabel' |
2 | 2 | ||
3 | local g = re.compile[[ | 3 | local g = re.compile[[ |
4 | S <- Id List | 4 | S <- Id List |
diff --git a/examples/listIdRe2.lua b/examples/listIdRe2.lua index 6bab6ba..58ddedd 100644 --- a/examples/listIdRe2.lua +++ b/examples/listIdRe2.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local re = require 'relabelrec' | 1 | local re = require 'relabel' |
2 | 2 | ||
3 | local errinfo = { | 3 | local errinfo = { |
4 | {"errUndef", "undefined"}, | 4 | {"errUndef", "undefined"}, |
diff --git a/examples/tiny.lua b/examples/tiny.lua index 784e031..734536c 100644 --- a/examples/tiny.lua +++ b/examples/tiny.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local re = require 'relabelrec' | 1 | local re = require 'relabel' |
2 | 2 | ||
3 | local terror = {} | 3 | local terror = {} |
4 | 4 | ||
diff --git a/examples/typedlua/tllexer.lua b/examples/typedlua/tllexer.lua index d6033ec..96f296d 100644 --- a/examples/typedlua/tllexer.lua +++ b/examples/typedlua/tllexer.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | local tllexer = {} | 1 | local tllexer = {} |
2 | 2 | ||
3 | local lpeg = require "lpeglabelrec" | 3 | local lpeg = require "lpeglabel" |
4 | lpeg.locale(lpeg) | 4 | lpeg.locale(lpeg) |
5 | 5 | ||
6 | local tlerror = require "tlerror" | 6 | local tlerror = require "tlerror" |
diff --git a/examples/typedlua/tlparser.lua b/examples/typedlua/tlparser.lua index fe4fd5e..a301fa6 100644 --- a/examples/typedlua/tlparser.lua +++ b/examples/typedlua/tlparser.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | local tlparser = {} | 1 | local tlparser = {} |
2 | 2 | ||
3 | local lpeg = require "lpeglabelrec" | 3 | local lpeg = require "lpeglabel" |
4 | lpeg.locale(lpeg) | 4 | lpeg.locale(lpeg) |
5 | 5 | ||
6 | local tllexer = require "tllexer" | 6 | local tllexer = require "tllexer" |
@@ -1348,8 +1348,8 @@ static struct luaL_Reg metareg[] = { | |||
1348 | }; | 1348 | }; |
1349 | 1349 | ||
1350 | 1350 | ||
1351 | int luaopen_lpeglabelrec (lua_State *L); /* labeled failure */ | 1351 | int luaopen_lpeglabel (lua_State *L); /* labeled failure */ |
1352 | int luaopen_lpeglabelrec (lua_State *L) { /* labeled failure */ | 1352 | int luaopen_lpeglabel (lua_State *L) { /* labeled failure */ |
1353 | luaL_newmetatable(L, PATTERN_T); | 1353 | luaL_newmetatable(L, PATTERN_T); |
1354 | lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ | 1354 | lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ |
1355 | lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); | 1355 | lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); |
@@ -1,4 +1,4 @@ | |||
1 | LIBNAME = lpeglabelrec | 1 | LIBNAME = lpeglabel |
2 | LUADIR = ../lua/ | 2 | LUADIR = ../lua/ |
3 | 3 | ||
4 | COPT = -O2 | 4 | COPT = -O2 |
@@ -29,24 +29,24 @@ FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o | |||
29 | 29 | ||
30 | # For Linux | 30 | # For Linux |
31 | linux: | 31 | linux: |
32 | make lpeglabelrec.so "DLLFLAGS = -shared -fPIC" | 32 | make lpeglabel.so "DLLFLAGS = -shared -fPIC" |
33 | 33 | ||
34 | # For Mac OS | 34 | # For Mac OS |
35 | macosx: | 35 | macosx: |
36 | make lpeglabelrec.so "DLLFLAGS = -bundle -undefined dynamic_lookup" | 36 | make lpeglabel.so "DLLFLAGS = -bundle -undefined dynamic_lookup" |
37 | 37 | ||
38 | lpeglabelrec.so: $(FILES) | 38 | lpeglabel.so: $(FILES) |
39 | env $(CC) $(DLLFLAGS) $(FILES) -o lpeglabelrec.so | 39 | env $(CC) $(DLLFLAGS) $(FILES) -o lpeglabel.so |
40 | 40 | ||
41 | $(FILES): makefile | 41 | $(FILES): makefile |
42 | 42 | ||
43 | test: test.lua testlabel.lua testerrors.lua relabel.lua lpeglabelrec.so | 43 | test: test.lua testlabel.lua testerrors.lua relabel.lua lpeglabel.so |
44 | lua test.lua | 44 | lua test.lua |
45 | lua testlabel.lua | 45 | lua testlabel.lua |
46 | lua testerrors.lua | 46 | lua testerrors.lua |
47 | 47 | ||
48 | clean: | 48 | clean: |
49 | rm -f $(FILES) lpeglabelrec.so | 49 | rm -f $(FILES) lpeglabel.so |
50 | 50 | ||
51 | 51 | ||
52 | lpcap.o: lpcap.c lpcap.h lptypes.h | 52 | lpcap.o: lpcap.c lpcap.h lptypes.h |
diff --git a/relabel.lua b/relabel.lua index af1a440..cf76e89 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -6,7 +6,7 @@ local pcall = pcall | |||
6 | local setmetatable = setmetatable | 6 | local setmetatable = setmetatable |
7 | local unpack, tinsert, concat = table.unpack or unpack, table.insert, table.concat | 7 | local unpack, tinsert, concat = table.unpack or unpack, table.insert, table.concat |
8 | local rep = string.rep | 8 | local rep = string.rep |
9 | local m = require"lpeglabelrec" | 9 | local m = require"lpeglabel" |
10 | 10 | ||
11 | -- 'm' will be used to parse expressions, and 'mm' will be used to | 11 | -- 'm' will be used to parse expressions, and 'mm' will be used to |
12 | -- create expressions; that is, 're' runs on 'm', creating patterns | 12 | -- create expressions; that is, 're' runs on 'm', creating patterns |
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | -- require"strict" -- just to be pedantic | 5 | -- require"strict" -- just to be pedantic |
6 | 6 | ||
7 | local m = require"lpeglabelrec" | 7 | local m = require"lpeglabel" |
8 | 8 | ||
9 | 9 | ||
10 | -- for general use | 10 | -- for general use |
@@ -1110,7 +1110,7 @@ checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'}) | |||
1110 | -- Tests for 're' module | 1110 | -- Tests for 're' module |
1111 | ------------------------------------------------------------------- | 1111 | ------------------------------------------------------------------- |
1112 | 1112 | ||
1113 | local re = require "relabelrec" | 1113 | local re = require "relabel" |
1114 | 1114 | ||
1115 | local match, compile = re.match, re.compile | 1115 | local match, compile = re.match, re.compile |
1116 | 1116 | ||
diff --git a/testlabel.lua b/testlabel.lua index d9bac64..9fcdcfc 100644 --- a/testlabel.lua +++ b/testlabel.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local m = require 'lpeglabelrec' | 1 | local m = require 'lpeglabel' |
2 | 2 | ||
3 | local p, r, l, s, serror | 3 | local p, r, l, s, serror |
4 | 4 | ||
@@ -363,7 +363,7 @@ assert(r == nil and l == 5 and serror == s) | |||
363 | print("+") | 363 | print("+") |
364 | 364 | ||
365 | 365 | ||
366 | local re = require 'relabelrec' | 366 | local re = require 'relabel' |
367 | 367 | ||
368 | g = re.compile[['a' //{4,9} [a-z] | 368 | g = re.compile[['a' //{4,9} [a-z] |
369 | ]] | 369 | ]] |
diff --git a/testrelabelparser.lua b/testrelabelparser.lua index 3f3ad41..5a43621 100644 --- a/testrelabelparser.lua +++ b/testrelabelparser.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local re = require 'relabelrec' | 1 | local re = require 'relabel' |
2 | 2 | ||
3 | function testerror(repatt, msg) | 3 | function testerror(repatt, msg) |
4 | msg = msg:match("^%s*(.-)%s*$") -- trim | 4 | msg = msg:match("^%s*(.-)%s*$") -- trim |