aboutsummaryrefslogtreecommitdiff
path: root/examples/listIdRe2.lua
diff options
context:
space:
mode:
authorSergio Medeiros <sqmedeiros@gmail.com>2015-03-23 15:09:08 -0300
committerSergio Medeiros <sqmedeiros@gmail.com>2015-03-23 15:09:08 -0300
commitf124b2d4449a13ac21af9581a44b4455d89eaddb (patch)
treee0486555ac811c5f712927f110bb7bcda8569adf /examples/listIdRe2.lua
parent0e93d536ba2d312502737cce2ab0cc21393c4842 (diff)
downloadlpeglabel-f124b2d4449a13ac21af9581a44b4455d89eaddb.tar.gz
lpeglabel-f124b2d4449a13ac21af9581a44b4455d89eaddb.tar.bz2
lpeglabel-f124b2d4449a13ac21af9581a44b4455d89eaddb.zip
Renaming "re.lua" to "relabel.lua".
Adding examples, README and lpeglabel.html
Diffstat (limited to 'examples/listIdRe2.lua')
-rw-r--r--examples/listIdRe2.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/listIdRe2.lua b/examples/listIdRe2.lua
new file mode 100644
index 0000000..67c42f1
--- /dev/null
+++ b/examples/listIdRe2.lua
@@ -0,0 +1,35 @@
1local re = require 're'
2
3local errUndef, errId, errComma = 0, 1, 2
4
5local terror = {
6 [errUndef] = "Error",
7 [errId] = "Error: expecting an identifier",
8 [errComma] = "Error: expecting ','",
9}
10
11local tlabels = { ["errUndef"] = errUndef,
12 ["errId"] = errId,
13 ["errComma"] = errComma }
14
15re.setlabels(tlabels)
16
17local g = re.compile[[
18 S <- Id List
19 List <- !. / (',' / %{errComma}) Id List
20 Id <- [a-z] / %{errId}
21]]
22
23function mymatch (g, s)
24 local r, e = g:match(s)
25 if not r then
26 return r, terror[e]
27 end
28 return r
29end
30
31print(mymatch(g, "a,b"))
32print(mymatch(g, "a b"))
33print(mymatch(g, ", b"))
34
35