From 31e4e7d98a3d08fe4ada6c3addefd11e2d39ed33 Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Sat, 9 Feb 2013 14:43:03 -0600 Subject: [PATCH] Fixed sort to avoid using unquoted keywords --- sort.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sort.lua b/sort.lua index a5ee036..1f9633b 100644 --- a/sort.lua +++ b/sort.lua @@ -80,11 +80,35 @@ local function quotedString(str) return string.gsub(string.format("%q", str), "\n", "n") end +local keywords = { + ["and"] = true, + ["break"] = true, + ["do"] = true, + ["else"] = true, + ["elseif"] = true, + ["end"] = true, + ["false"] = true, + ["for"] = true, + ["function"] = true, + ["if"] = true, + ["in"] = true, + ["local"] = true, + ["nil"] = true, + ["not"] = true, + ["or"] = true, + ["repeat"] = true, + ["return"] = true, + ["then"] = true, + ["true"] = true, + ["until"] = true, + ["while"] = true, +} + local function varName(name) if type(name) == "number" then return string.format("[%d]", name) elseif type(name) == "string" then - if name:find("^%a[%w_]+$") then + if name:find("^%a[%w_]+$") and not keywords[name] then return name else return string.format("[%s]", quotedString(name)) -- 1.7.9.5