Permalink
Browse files

escape dot chains that are lua keywords

  • Loading branch information...
1 parent b7bf9b7 commit 867989b4f777d966cb7a7f72e908a527e9154ec9 @leafo committed Oct 1, 2012
Showing with 27 additions and 1 deletion.
  1. +13 −0 moonscript/transform.lua
  2. +6 −0 moonscript/transform.moon
  3. +5 −0 tests/inputs/syntax.moon
  4. +3 −1 tests/outputs/syntax.lua
View
@@ -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",
@@ -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
@@ -227,4 +227,9 @@ a *= 3 + 5
a *= 3
a /= func "cool"
+---
+
+x.then = "hello"
+x.while.true = "hello"
+
-- cooool
View
@@ -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"

0 comments on commit 867989b

Please sign in to comment.