aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2017-01-04 14:50:41 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2017-01-04 14:50:41 -0300
commit02b61c3bcbda1b42959ecdf23750647f573f58af (patch)
treeac8dec513542b5937b962c60fc6d53a1b05af45c /examples
parente0feb1b3a659411d53b231d24929c4b7b4d92431 (diff)
downloadlpeglabel-02b61c3bcbda1b42959ecdf23750647f573f58af.tar.gz
lpeglabel-02b61c3bcbda1b42959ecdf23750647f573f58af.tar.bz2
lpeglabel-02b61c3bcbda1b42959ecdf23750647f573f58af.zip
Adding to README an example about farthest failure
Diffstat (limited to 'examples')
-rw-r--r--examples/farthest.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/examples/farthest.lua b/examples/farthest.lua
new file mode 100644
index 0000000..692390f
--- /dev/null
+++ b/examples/farthest.lua
@@ -0,0 +1,14 @@
1local m = require'lpeglabel'
2
3function matchPrint(p, s)
4 local r, lab, sfail = p:match(s)
5 print("r: ", r, "lab: ", lab, "sfail: ", sfail)
6end
7
8local p = m.P"a"^0 * m.P"b" + m.P"c"
9matchPrint(p, "abc") --> r: 3 lab: nil sfail: nil
10matchPrint(p, "c") --> r: 2 lab: nil sfail: nil
11matchPrint(p, "aac") --> r: nil lab: 0 sfail: c
12matchPrint(p, "xxc") --> r: nil lab: 0 sfail: xxc
13
14