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
if file then
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'
end
local sz = #s
local idx = 1
if sz == 0 then return nil end -- empty file
--print('sz',sz)
while true do
for _,m in ipairs(matches) do

View File

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