Skip to content

Commit

Permalink
Support calling lexer.lineno several times in a row
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Feb 2, 2016
1 parent 1923361 commit 5baf4d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lua/pl/lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,26 @@ function lexer.scan(s,matches,filter,options)
local _, newlines = tok:gsub("\n", {})
line_nr = line_nr + newlines
end
if res then
while res do
local tp = type(res)
-- insert a token list
if tp == 'table' then
yield('','')
res = yield('','')
for _,t in ipairs(res) do
yield(t[1],t[2])
res = yield(t[1],t[2])
end
elseif tp == 'string' then -- or search up to some special pattern
i1,i2 = strfind(s,res,idx)
if i1 then
tok = strsub(s,i1,i2)
idx = i2 + 1
yield('',tok)
res = yield('',tok)
else
yield('','')
res = yield('','')
idx = sz + 1
end
else
yield(line_nr,idx)
res = yield(line_nr,idx)
end
end

Expand Down
1 change: 1 addition & 0 deletions tests/test-lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ bar

iter()
asserteq(lexer.lineno(iter), 1)
asserteq(lexer.lineno(iter), 1)
iter()
asserteq(lexer.lineno(iter), 2)

0 comments on commit 5baf4d0

Please sign in to comment.