Skip to content

Commit

Permalink
Fix pretty.read failing on 'function' within strings
Browse files Browse the repository at this point in the history
Apply fix suggested by @rvandermate. Fixes lunarmodules#172.
  • Loading branch information
mpeterv committed Nov 13, 2015
1 parent 2c02bda commit 48bae74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/pl/pretty.lua
Expand Up @@ -66,7 +66,7 @@ function pretty.read(s)
if s:find '[^\'"%w_]function[^\'"%w_]' then
local tok = lexer.lua(s)
for t,v in tok do
if t == 'keyword' then
if t == 'keyword' and v == 'function' then
return nil,"cannot have functions in table definition"
end
end
Expand Down
12 changes: 10 additions & 2 deletions tests/test-pretty.lua
Expand Up @@ -28,8 +28,16 @@ assert(res)

res,err = pretty.read [[
{
['function'] = true,
['do'] = function() return end
['function'] = true,
['do'] = "no function here...",
}
]]
assert(res)

res,err = pretty.read [[
{
['function'] = true,
['do'] = function() return end
}
]]
assertmatch(err,'cannot have functions in table definition')
Expand Down

0 comments on commit 48bae74

Please sign in to comment.