allow lua keyword property access on self #410

This commit is contained in:
leaf corcoran 2022-11-04 13:07:16 -07:00
parent 0af9a8df8c
commit 1ba34563f9
5 changed files with 55 additions and 5 deletions

View File

@ -76,7 +76,8 @@ do
_continue_0 = true _continue_0 = true
break break
end end
names_by_position[pos] = names_by_position[pos] or { } local _update_0 = pos
names_by_position[_update_0] = names_by_position[_update_0] or { }
insert(names_by_position[pos], name) insert(names_by_position[pos], name)
_continue_0 = true _continue_0 = true
until true until true

View File

@ -296,10 +296,44 @@ return {
return self:line("not ", self:value(node[2])) return self:line("not ", self:value(node[2]))
end, end,
self = function(self, node) self = function(self, node)
return "self." .. self:name(node[2]) if data.lua_keywords[node[2]] then
return self:value({
"chain",
"self",
{
"index",
{
"string",
'"',
node[2]
}
}
})
else
return "self." .. self:name(node[2])
end
end, end,
self_class = function(self, node) self_class = function(self, node)
return "self.__class." .. self:name(node[2]) if data.lua_keywords[node[2]] then
return self:value({
"chain",
"self",
{
"dot",
"__class"
},
{
"index",
{
"string",
'"',
node[2]
}
}
})
else
return "self.__class." .. self:name(node[2])
end
end, end,
self_colon = function(self, node) self_colon = function(self, node)
return "self:" .. self:name(node[2]) return "self:" .. self:name(node[2])

View File

@ -183,10 +183,20 @@ string_chars = {
@line "not ", @value node[2] @line "not ", @value node[2]
self: (node) => self: (node) =>
"self."..@name node[2] if data.lua_keywords[node[2]]
@value {"chain", "self", {"index", {
"string", '"', node[2]
}}}
else
"self."..@name node[2]
self_class: (node) => self_class: (node) =>
"self.__class."..@name node[2] if data.lua_keywords[node[2]]
@value {"chain", "self", {"dot", "__class"}, {"index", {
"string", '"', node[2]
}}}
else
"self.__class."..@name node[2]
self_colon: (node) => self_colon: (node) =>
"self:"..@name node[2] "self:"..@name node[2]

View File

@ -158,6 +158,9 @@ hello ..= "world"
@@something += 10 @@something += 10
@something += 10 @something += 10
@@then += 10
@then += 10
a["hello"] += 10 a["hello"] += 10
a["hello#{tostring ff}"] += 10 a["hello#{tostring ff}"] += 10
a[four].x += 10 a[four].x += 10

View File

@ -162,6 +162,8 @@ local m = m % 2
local hello = hello .. "world" local hello = hello .. "world"
self.__class.something = self.__class.something + 10 self.__class.something = self.__class.something + 10
self.something = self.something + 10 self.something = self.something + 10
self.__class["then"] = self.__class["then"] + 10
self["then"] = self["then"] + 10
local _update_0 = "hello" local _update_0 = "hello"
a[_update_0] = a[_update_0] + 10 a[_update_0] = a[_update_0] + 10
local _update_1 = "hello" .. tostring(tostring(ff)) local _update_1 = "hello" .. tostring(tostring(ff))