escape dot chains that are lua keywords

This commit is contained in:
leaf corcoran 2012-10-01 15:12:01 -07:00
parent b7bf9b73d0
commit 867989b4f7
4 changed files with 27 additions and 1 deletions

View File

@ -1271,6 +1271,19 @@ Value = Transformer({
end, end,
chain = function(self, node) chain = function(self, node)
local stub = node[#node] local stub = node[#node]
for i = 3, #node do
local part = node[i]
if ntype(part) == "dot" and data.lua_keywords[part[2]] then
node[i] = {
"index",
{
"string",
'"',
part[2]
}
}
end
end
if ntype(node[2]) == "string" then if ntype(node[2]) == "string" then
node[2] = { node[2] = {
"parens", "parens",

View File

@ -680,6 +680,12 @@ Value = Transformer {
chain: (node) => chain: (node) =>
stub = node[#node] stub = node[#node]
-- escape lua keywords used in dot accessors
for i=3,#node
part = node[i]
if ntype(part) == "dot" and data.lua_keywords[part[2]]
node[i] = { "index", {"string", '"', part[2]} }
if ntype(node[2]) == "string" if ntype(node[2]) == "string"
-- add parens if callee is raw string -- add parens if callee is raw string
node[2] = {"parens", node[2] } node[2] = {"parens", node[2] }

View File

@ -227,4 +227,9 @@ a *= 3 + 5
a *= 3 a *= 3
a /= func "cool" a /= func "cool"
---
x.then = "hello"
x.while.true = "hello"
-- cooool -- cooool

View File

@ -227,3 +227,5 @@ a = a + (3 - 5)
a = a * (3 + 5) a = a * (3 + 5)
a = a * 3 a = a * 3
a = a / func("cool") a = a / func("cool")
x["then"] = "hello"
x["while"]["true"] = "hello"