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