aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-09 14:36:15 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-09 14:37:22 -0800
commit7d2b7199d87930096b7fd799709fe0105d51eccb (patch)
treef33de61cb44357497758bb08ec6993753d8baa43 /nomsu_compiler.moon
parentba96cdfa07cea15ada62f8f89b2563de1286a0de (diff)
Lots of cleanups, including expanded use of (... compiles to "text
literal") shorthand, deprecating Lua value, and more use of Lua "..." with text interpolations.
Diffstat (limited to 'nomsu_compiler.moon')
-rw-r--r--nomsu_compiler.moon15
1 files changed, 8 insertions, 7 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 8c21eef..847da21 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -30,11 +30,11 @@ pretty_error = require("pretty_errors")
compile_error = (tree, err_msg, hint=nil)->
err_str = pretty_error{
title: "Compile error"
- error:err_msg, hint:hint, source:tree\get_source_code!
+ error:err_msg, hint:hint, source:tree\get_source_file!
start:tree.source.start, stop:tree.source.stop, filename:tree.source.filename
}
error(err_str, 0)
-
+{:tree_to_nomsu, :tree_to_inline_nomsu} = require "nomsu_decompiler"
-- This is a bit of a hack, but this code handles arbitrarily complex
-- math expressions like 2*x + 3^2 without having to define a single
@@ -88,9 +88,6 @@ compile = setmetatable({
return lua
return operate_on_text code
- -- TODO: remove shim
- ["Lua value"]: (compile, tree, code)-> compile.action["Lua"](compile, tree, code)
-
["lua >"]: (compile, tree, code)->
if code.type != "Text"
return tree
@@ -116,8 +113,12 @@ compile = setmetatable({
["tests"]: (compile, tree)-> LuaCode(tree.source, "TESTS")
["test"]: (compile, tree, body)->
- -- TODO: maybe go back to storing nomsu code instead of syntax tree
- LuaCode tree.source, "TESTS[#{tostring(tree.source)\as_lua!}] = ", body\as_lua!
+ unless body.type == 'Block'
+ compile_error(tree, "This should be a Block")
+ test_nomsu = body\get_source_code!\match(":[ ]*(.*)")
+ if indent = test_nomsu\match("\n([ ]*)")
+ test_nomsu = test_nomsu\gsub("\n"..indent, "\n")
+ LuaCode tree.source, "TESTS[#{tostring(tree.source)\as_lua!}] = ", test_nomsu\as_lua!
["is jit"]: (compile, tree, code)-> LuaCode(tree.source, "jit")
["Lua version"]: (compile, tree, code)-> LuaCode(tree.source, "_VERSION")