lexer would hang on an empty file

This commit is contained in:
steve donovan 2011-07-11 09:34:18 +02:00
parent 2e016bbe65
commit d864e49f47
2 changed files with 3 additions and 1 deletions

View File

@ -156,11 +156,12 @@ function lexer.scan (s,matches,filter,options)
local line = 1 local line = 1
if file then if file then
s = file:read() s = file:read()
if not s then return nil end -- empty file if not s or s == '' then return nil end -- empty file
s = s ..'\n' s = s ..'\n'
end end
local sz = #s local sz = #s
local idx = 1 local idx = 1
if sz == 0 then return nil end -- empty file
--print('sz',sz) --print('sz',sz)
while true do while true do
for _,m in ipairs(matches) do for _,m in ipairs(matches) do

View File

@ -39,6 +39,7 @@ function prettify.lua (file)
local tok = lexer.lua(code,{},{}) local tok = lexer.lua(code,{},{})
local t,val = tok() local t,val = tok()
if not t then return nil,"empty file" end
while t do while t do
val = escape(val) val = escape(val)
if spans[t] then if spans[t] then