From d218dcbd4217a8881f9a3e500ba17cd24e6e77f8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 7 Sep 2017 09:38:54 -0700 Subject: Added comments. --- core.moon | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'core.moon') diff --git a/core.moon b/core.moon index a0d105a..1420898 100755 --- a/core.moon +++ b/core.moon @@ -39,17 +39,24 @@ g = PermissionNomic() g\defmacro [[lua %lua_code]], (vars,helpers,ftype)=> with helpers lua_code = vars.lua_code.value - escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r" - unescape = (s)-> s\gsub("\\(.)", ((c)-> escapes[c] or c)) + as_lua_code = (str)-> + switch str.type + when "String" + escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r" + unescaped = str.value\gsub("\\(.)", ((c)-> escapes[c] or c)) + return unescaped + + when "Longstring" + result = [line for line in str.value\gmatch("[ \t]*|([^\n]*)")] + return table.concat(result, "\n") + else + return str.value + switch lua_code.type when "List" -- TODO: handle subexpressions - .lua table.concat[unescape(i.value.value) for i in *lua_code.value] - when "String" - .lua(unescape(lua_code.value)) - when "Longstring" - .lua(lua_code.value) - else error("Unknown type: #{lua_code.type}") + .lua table.concat[as_lua_code(i.value) for i in *lua_code.value] + else .lua(as_lua_code(lua_code)) return nil g\def {"restrict %fn to %whitelist"}, (vars)=> @@ -106,6 +113,9 @@ g\def [[printf %str]], (args)=> for s in *args.str do io.write(utils.repr(s)) io.write("\n") +g\def [[concat %strs]], (vars)=> + return table.concat([utils.repr(s) for s in *vars.strs], "") + g\def [[quote %str]], (vars)=> return utils.repr(vars.str, true) -- cgit v1.2.3