diff options
author | Sergio Medeiros <sqmedeiros@gmail.com> | 2015-03-23 15:09:08 -0300 |
---|---|---|
committer | Sergio Medeiros <sqmedeiros@gmail.com> | 2015-03-23 15:09:08 -0300 |
commit | f124b2d4449a13ac21af9581a44b4455d89eaddb (patch) | |
tree | e0486555ac811c5f712927f110bb7bcda8569adf /examples/listIdRe1.lua | |
parent | 0e93d536ba2d312502737cce2ab0cc21393c4842 (diff) | |
download | lpeglabel-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.lua | 27 |
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 @@ | |||
1 | local re = require 're' | ||
2 | |||
3 | local g = re.compile[[ | ||
4 | S <- Id List | ||
5 | List <- !. / (',' / %{2}) Id List | ||
6 | Id <- [a-z] / %{1} | ||
7 | ]] | ||
8 | |||
9 | function 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 | ||
21 | end | ||
22 | |||
23 | print(mymatch(g, "a,b")) | ||
24 | print(mymatch(g, "a b")) | ||
25 | print(mymatch(g, ", b")) | ||
26 | |||
27 | |||