aboutsummaryrefslogtreecommitdiff
path: root/examples/listId1.lua
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2016-07-01 14:57:39 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2016-07-01 14:57:39 -0300
commit7cd05bfaeea0fc1d269ace114d3225bffbd82940 (patch)
tree955ed449edeed25506a3b47977840d642dad5026 /examples/listId1.lua
parent6a3c4bfddcfaa0e1348aa2c3d9fb7135a4f330c8 (diff)
downloadlpeglabel-7cd05bfaeea0fc1d269ace114d3225bffbd82940.tar.gz
lpeglabel-7cd05bfaeea0fc1d269ace114d3225bffbd82940.tar.bz2
lpeglabel-7cd05bfaeea0fc1d269ace114d3225bffbd82940.zip
Adding function 'calcline' to relabel and updating documentation/examples
Diffstat (limited to 'examples/listId1.lua')
-rw-r--r--examples/listId1.lua11
1 files changed, 2 insertions, 9 deletions
diff --git a/examples/listId1.lua b/examples/listId1.lua
index 12c0678..8976f5f 100644
--- a/examples/listId1.lua
+++ b/examples/listId1.lua
@@ -1,11 +1,5 @@
1local m = require'lpeglabel' 1local m = require'lpeglabel'
2 2local re = require'relabel'
3local function calcline (s, i)
4 if i == 1 then return 1, 1 end
5 local rest, line = s:sub(1,i):gsub("[^\n]*\n", "")
6 local col = #rest
7 return 1 + line, col ~= 0 and col or 1
8end
9 3
10local g = m.P{ 4local g = m.P{
11 "S", 5 "S",
@@ -19,7 +13,7 @@ local g = m.P{
19function mymatch (g, s) 13function mymatch (g, s)
20 local r, e, sfail = g:match(s) 14 local r, e, sfail = g:match(s)
21 if not r then 15 if not r then
22 local line, col = calcline(s, #s - #sfail) 16 local line, col = re.calcline(s, #s - #sfail)
23 local msg = "Error at line " .. line .. " (col " .. col .. ")" 17 local msg = "Error at line " .. line .. " (col " .. col .. ")"
24 if e == 1 then 18 if e == 1 then
25 return r, msg .. ": expecting an identifier before '" .. sfail .. "'" 19 return r, msg .. ": expecting an identifier before '" .. sfail .. "'"
@@ -35,4 +29,3 @@ end
35print(mymatch(g, "one,two")) 29print(mymatch(g, "one,two"))
36print(mymatch(g, "one two")) 30print(mymatch(g, "one two"))
37print(mymatch(g, "one,\n two,\nthree,")) 31print(mymatch(g, "one,\n two,\nthree,"))
38