aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-10-19 18:16:15 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-10-19 18:16:15 -0700
commitca5896b7bd8579e42a7fc9601e00512518051432 (patch)
treeaf356f2a5f2ed22b580f4b19f5fce5ee15a66ef2 /lib
parentc7994cf72043936db1a5023c8475b0b64e0aaa21 (diff)
Finally fixed the bullshit way that string literals were converted to lua.
Diffstat (limited to 'lib')
-rw-r--r--lib/metaprogramming.nom29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom
index d167fef..4feae46 100644
--- a/lib/metaprogramming.nom
+++ b/lib/metaprogramming.nom
@@ -16,13 +16,22 @@ lua> ".."
rule [escaped parse %shorthand as %longhand] =:
lua> ".."
|local aliases = nomsu:get_stubs(nomsu:typecheck(vars, "shorthand", "List").value);
- |if #vars.longhand.value ~= 1 then;
- | nomsu:error("Expected only 1 line to parse to, but got "..tostring(#vars.longhand.value));
- |end;
- |local template = nomsu:typecheck(vars, "longhand", "Thunk").value[1];
+ |local template = nomsu:typecheck(vars, "longhand", "Thunk").value;
|local function parsing_as(nomsu, vars)
- | local replacement = nomsu:replaced_vars(template, vars);
- | return nomsu:tree_to_lua(replacement);
+ # Single expression/statement
+ | if #template == 1 then;
+ | local replacement = nomsu:replaced_vars(template[1], vars);
+ | return nomsu:tree_to_lua(replacement);
+ | end
+ # Multiple statements
+ | local lua_bits = {};
+ | for _,bit in ipairs(template) do;
+ | bit = nomsu:replaced_vars(bit, vars);
+ | local expr, statement = nomsu:tree_to_lua(bit);
+ | if statement then; table.insert(lua_bits, statement); end;
+ | if expr then; table.insert(lua_bits, "ret = "..expr..";"); end;
+ | end;
+ | return nil, table.concat(lua_bits, "\\n");
|end;
|nomsu:defmacro(aliases, parsing_as, template.src);
escaped parse \[parse %shorthand as %longhand] as \: escaped parse \%shorthand as \%longhand
@@ -56,10 +65,10 @@ compile [repr %obj] to:
compile [type %obj, type of %obj] to:
"type(\(%obj as lua))"
-parse [lua do> %block] as: lua> ".."
- |do;
- | \(%block)
- |end;
+parse [lua do> %block] as:
+ lua> "do;"
+ lua> %block
+ lua> "end;"
rule [%tree as lua statement] =:
lua do> ".."
|local _,statement = nomsu:tree_to_lua(\(%tree));