aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/core/operators.nom4
-rw-r--r--nomsu.7.peg2
-rw-r--r--nomsu_compiler.lua11
-rw-r--r--nomsu_compiler.moon8
4 files changed, 22 insertions, 3 deletions
diff --git a/lib/core/operators.nom b/lib/core/operators.nom
index 187d2c7..dbc0b18 100644
--- a/lib/core/operators.nom
+++ b/lib/core/operators.nom
@@ -43,7 +43,7 @@ test:
if i > 1 then lua:add(", ") end
local assignment_lua = \($assignment as lua expr)
lua:add(assignment_lua)
- if \$assignment.type == 'Var' then
+ if \$assignment.type == 'Var' and \$assignment[1].type ~= "MethodCall" then
lua:add_free_vars({assignment_lua:text()})
end
end
@@ -67,7 +67,7 @@ test:
else
local var_lua = \($var as lua expr)
lua:add(var_lua)
- if \$var.type == 'Var' then
+ if \$var.type == 'Var' and \$var[1].type ~= "MethodCall" then
lua:add_free_vars({var_lua:text()})
end
lua:add(' = ', \($value as lua expr), ';')
diff --git a/nomsu.7.peg b/nomsu.7.peg
index 650623c..18ef9ae 100644
--- a/nomsu.7.peg
+++ b/nomsu.7.peg
@@ -189,7 +189,7 @@ real_number (Number) <-
{ (%at_break "-")? [0-9]+ (("_"+->"") [0-9]+)* "." [0-9]+ (("_"+->"") [0-9]+)* }
-variable (Var) <- "$" ({ident_char+} / "(" ws* (inline_action / variable) ws* ")" / {''})
+variable (Var) <- "$" ({ident_char+} / "(" ws* (inline_methodchain / inline_action / variable) ws* ")" / {''})
inline_list (List) <-
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 5495fde..4bdac9a 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -73,6 +73,9 @@ local math_expression = re.compile([[ (([*/^+-] / [0-9]+) " ")* [*/^+-] !. ]])
local MAX_LINE = 80
local compile
compile = function(self, tree)
+ if tree == nil then
+ error("No tree was passed in.")
+ end
if tree.version and tree.version < self.NOMSU_VERSION:up_to(#tree.version) and self._1_upgraded_from_2_to then
tree = self._1_upgraded_from_2_to(tree, tree.version, self.NOMSU_VERSION)
end
@@ -259,6 +262,11 @@ compile = function(self, tree)
elseif "Block" == _exp_0 then
local lua = LuaCode:from(tree.source)
for i, line in ipairs(tree) do
+ if line.type == "Error" then
+ return self:compile(line)
+ end
+ end
+ for i, line in ipairs(tree) do
if i > 1 then
lua:add("\n")
end
@@ -427,6 +435,9 @@ compile = function(self, tree)
local number = tostring(tree[1]):gsub("_", "")
return LuaCode:from(tree.source, number)
elseif "Var" == _exp_0 then
+ if tree[1].type == "MethodCall" then
+ return LuaCode:from(tree.source, self:compile(tree[1][1]), ".", tree[1][2]:get_stub():as_lua_id())
+ end
return LuaCode:from(tree.source, tree:as_var():as_lua_id())
elseif "FileChunks" == _exp_0 then
return error("Can't convert FileChunks to a single block of lua, since each chunk's " .. "compilation depends on the earlier chunks")
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 4b684a4..4019632 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -62,6 +62,9 @@ math_expression = re.compile [[ (([*/^+-] / [0-9]+) " ")* [*/^+-] !. ]]
MAX_LINE = 80 -- For beautification purposes, try not to make lines much longer than this value
compile = (tree)=>
+ if tree == nil
+ error("No tree was passed in.")
+
-- Automatically upgrade trees from older versions:
if tree.version and tree.version < @NOMSU_VERSION\up_to(#tree.version) and @_1_upgraded_from_2_to
tree = @._1_upgraded_from_2_to(tree, tree.version, @NOMSU_VERSION)
@@ -211,6 +214,9 @@ compile = (tree)=>
when "Block"
lua = LuaCode\from(tree.source)
for i, line in ipairs tree
+ if line.type == "Error"
+ return @compile(line)
+ for i, line in ipairs tree
if i > 1 then lua\add "\n"
line_lua = @compile(line)
lua\add line_lua
@@ -345,6 +351,8 @@ compile = (tree)=>
return LuaCode\from(tree.source, number)
when "Var"
+ if tree[1].type == "MethodCall"
+ return LuaCode\from(tree.source, @compile(tree[1][1]), ".", tree[1][2]\get_stub!\as_lua_id!)
return LuaCode\from(tree.source, tree\as_var!\as_lua_id!)
when "FileChunks"