Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

escape dot chains that are lua keywords

  • Loading branch information...
commit 867989b4f777d966cb7a7f72e908a527e9154ec9 1 parent b7bf9b7
@leafo authored
View
13 moonscript/transform.lua
@@ -1271,6 +1271,19 @@ Value = Transformer({
end,
chain = function(self, 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
node[2] = {
"parens",
View
6 moonscript/transform.moon
@@ -680,6 +680,12 @@ Value = Transformer {
chain: (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"
-- add parens if callee is raw string
node[2] = {"parens", node[2] }
View
5 tests/inputs/syntax.moon
@@ -227,4 +227,9 @@ a *= 3 + 5
a *= 3
a /= func "cool"
+---
+
+x.then = "hello"
+x.while.true = "hello"
+
-- cooool
View
4 tests/outputs/syntax.lua
@@ -226,4 +226,6 @@ another(hello, one, two, three, four, {
a = a + (3 - 5)
a = a * (3 + 5)
a = a * 3
-a = a / func("cool")
+a = a / func("cool")
+x["then"] = "hello"
+x["while"]["true"] = "hello"
Please sign in to comment.
Something went wrong with that request. Please try again.