aboutsummaryrefslogtreecommitdiff
path: root/nomic.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-08-22 04:15:13 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-08-22 04:15:13 -0700
commitea69b181982a50771af0e6f2be262a63e06790da (patch)
tree376ab7b64c02b09081ffce273afb0c4f65351cd9 /nomic.moon
parent039c620df270e88f6d50df677b7dedd65b868449 (diff)
Slightly cleaned up macros.
Diffstat (limited to 'nomic.moon')
-rw-r--r--nomic.moon24
1 files changed, 14 insertions, 10 deletions
diff --git a/nomic.moon b/nomic.moon
index cbe6c8a..13f99bd 100644
--- a/nomic.moon
+++ b/nomic.moon
@@ -79,6 +79,7 @@ lingo = [=[
(({ {|
(expression (%word_boundary fn_bit)+) / (word (%word_boundary fn_bit)*)
|} }) -> FunctionCall)
+ / (expression)
}) -> Statement)
|} }) -> Block
@@ -222,7 +223,7 @@ class Game
print(code)
lua_thunk, err = loadstring(code)
if not lua_thunk
- error("Failed to compile generated code:\n#{code}")
+ error("Failed to compile generated code:\n#{code}\n\n#{err}")
action = lua_thunk!
if @debug
print("Running...")
@@ -299,7 +300,7 @@ class Game
when "Errors"
-- TODO: Better error reporting via tree.src
- error("\nParse error on: #{tree.value}")
+ error("\nParse error on: #{utils.repr(tree.value\match("[^\n]*"), true)}")
when "Block"
for chunk in *tree.value
@@ -317,14 +318,19 @@ class Game
lua "end)"
when "Statement"
- ret = transform(tree.value)
- return ret
+ if tree.value.type == "FunctionCall"
+ name_bits = {}
+ for token in *tree.value.value
+ table.insert name_bits, if token.type == "Word" then token.value else "%"
+ name = table.concat(name_bits, " ")
+ if @macros[name]
+ lua transform(tree.value)
+ ret = table.concat ret_lines, "\n"
+ return ret
+ lua "ret = #{ded(transform(tree.value))}"
when "Expression"
- ret = transform(tree.value)
- if parent.type == "Statement"
- ret = "ret = "..ded(ret)
- return ret
+ lua transform(tree.value)
when "FunctionCall"
name_bits = {}
@@ -341,8 +347,6 @@ class Game
m = fn(self, args, helpers, parent.type)
if m != nil then return m
else
- if parent.type == "Statement"
- lua "ret ="
args = [ded(transform(a)) for a in *tree.value when a.type != "Word"]
table.insert args, 1, utils.repr(name, true)
comma_separated_items("game:call(", args, ")")