nomsu/lib/moonscript.nom

31 lines
1.2 KiB
Plaintext

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