From 48bae74e13e4432a9b57bbaf38d0493027b3a9e0 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Fri, 13 Nov 2015 11:10:49 +0300 Subject: [PATCH] Fix pretty.read failing on 'function' within strings Apply fix suggested by @rvandermate. Fixes #172. --- lua/pl/pretty.lua | 2 +- tests/test-pretty.lua | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lua/pl/pretty.lua b/lua/pl/pretty.lua index d57bff57..953b4cb1 100644 --- a/lua/pl/pretty.lua +++ b/lua/pl/pretty.lua @@ -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 diff --git a/tests/test-pretty.lua b/tests/test-pretty.lua index 0516d2f6..5ddf220f 100644 --- a/tests/test-pretty.lua +++ b/tests/test-pretty.lua @@ -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')