diff options
author | Sergio Queiroz <sqmedeiros@gmail.com> | 2016-07-01 14:57:39 -0300 |
---|---|---|
committer | Sergio Queiroz <sqmedeiros@gmail.com> | 2016-07-01 14:57:39 -0300 |
commit | 7cd05bfaeea0fc1d269ace114d3225bffbd82940 (patch) | |
tree | 955ed449edeed25506a3b47977840d642dad5026 /examples/listId1.lua | |
parent | 6a3c4bfddcfaa0e1348aa2c3d9fb7135a4f330c8 (diff) | |
download | lpeglabel-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.lua | 11 |
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 @@ | |||
1 | local m = require'lpeglabel' | 1 | local m = require'lpeglabel' |
2 | 2 | local re = require'relabel' | |
3 | local 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 | ||
8 | end | ||
9 | 3 | ||
10 | local g = m.P{ | 4 | local g = m.P{ |
11 | "S", | 5 | "S", |
@@ -19,7 +13,7 @@ local g = m.P{ | |||
19 | function mymatch (g, s) | 13 | function 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 | |||
35 | print(mymatch(g, "one,two")) | 29 | print(mymatch(g, "one,two")) |
36 | print(mymatch(g, "one two")) | 30 | print(mymatch(g, "one two")) |
37 | print(mymatch(g, "one,\n two,\nthree,")) | 31 | print(mymatch(g, "one,\n two,\nthree,")) |
38 | |||