aboutsummaryrefslogtreecommitdiff
path: root/examples/listIdRe1.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/listIdRe1.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/listIdRe1.lua')
-rw-r--r--examples/listIdRe1.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/listIdRe1.lua b/examples/listIdRe1.lua
new file mode 100644
index 0000000..c75bb1d
--- /dev/null
+++ b/examples/listIdRe1.lua
@@ -0,0 +1,27 @@
1local re = require 're'
2
3local g = re.compile[[
4 S <- Id List
5 List <- !. / (',' / %{2}) Id List
6 Id <- [a-z] / %{1}
7]]
8
9function mymatch (g, s)
10 local r, e = g:match(s)
11 if not r then
12 if e == 1 then
13 return r, "Error: expecting an identifier"
14 elseif e == 2 then
15 return r, "Error: expecting ','"
16 else
17 return r, "Error"
18 end
19 end
20 return r
21end
22
23print(mymatch(g, "a,b"))
24print(mymatch(g, "a b"))
25print(mymatch(g, ", b"))
26
27