nomsu/lib/moonscript.nom
2017-09-21 00:10:26 -07:00

31 lines
1.3 KiB
Plaintext

require "lib/metaprogramming.nom"
# Moonscript!
macro block [moonscript block %moonscript_code] =:
lua block ".."
|local parse, compile = require('moonscript.parse'), require('moonscript.compile')
|local moon_code = compiler:tree_to_value(vars.moonscript_code, vars)
|local tree, err = parse.string(moon_code)
|if not tree then
| compiler:error("Failed to parse moonscript: "..err)
|end
|local lua_code, err, pos = compile.tree(tree)
|if not lua_code then
| compiler:error(compile.format_error(err, pos, moon_code))
|end
|return "do\\n"..lua_code.."\\nend"
macro [moonscript %moonscript_code] =:
lua block ".."
|local parse, compile = require('moonscript.parse'), require('moonscript.compile')
|local moon_code = compiler:tree_to_value(vars.moonscript_code, vars)
|local tree, err = parse.string(moon_code)
|if not tree then
| compiler:error("Failed to parse moonscript: "..err)
|end
|local lua_code, err, pos = compile.tree(tree)
|if not lua_code then
| compiler:error(compile.format_error(err, pos, moon_code))
|end
|return "(function(compiler, vars)\\n"..lua_code.."\\nend)(compiler, vars)"