aboutsummaryrefslogtreecommitdiff
path: root/lib/utils2.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils2.nom')
-rw-r--r--lib/utils2.nom63
1 files changed, 0 insertions, 63 deletions
diff --git a/lib/utils2.nom b/lib/utils2.nom
deleted file mode 100644
index c5da98e..0000000
--- a/lib/utils2.nom
+++ /dev/null
@@ -1,63 +0,0 @@
-use "lib/metaprogramming.nom"
-use "lib/utils.nom"
-use "lib/control_flow.nom"
-use "lib/operators.nom"
-use "lib/collections.nom"
-
-
-compile [say %str] to:
- "nomsu:writeln(\(%str as lua))" if ((%str's "type") is "Text")
- ..else "nomsu:writeln(nomsu:stringify(\(%str as lua)))"
-
-compile [do %action] to code:
- (%action as lua statements) if ((%action's "type") is "Block")
- ..else "(\(%action as lua))(nomsu);"
-
-# With statement
-compile [with %assignments %action] to code:
- set %data = []
- for %i = %assignment in (%assignments' "value"):
- set %tokens = (%assignment's "value")
- set %var = (%tokens -> 1)
- set %eq = (%tokens -> 2)
- assume (=lua "\%eq and \%eq.type == 'Word' and \%eq.value == '='") or barf ".."
- Invalid format for 'with' statement. List entries must have the form %var = (value)
- set %value = (%tokens -> 3)
- add {i=%i, var=%var, value=%value} to %data
- set %setup = (..)
- join (..)
- "local old_value\(%->"i") = \((%->"var") as lua); \((%->"var") as lua) = \((%->"value") as lua);"
- ..for all %data
- ..with glue "\n "
- return ".."
- do
- \%setup
- local fell_through = false;
- local ok, ret1, ret2 = pcall(function(nomsu)
- \(%action as lua statements);
- fell_through = true;
- end, nomsu);
- \(join ("\((%->"var") as lua) = old_value\(%->"i");" for all %data) with glue "\n ")
- if not ok then nomsu:error(ret1); end
- if not fell_through then
- return ret1, ret2;
- end
- end
-parse [with %thing = %value %action] as: with [%thing = %value] %action
-
-# Any/all/none
-compile [all of %items, all %items] to:
- "(\(join ((% as lua) for all (%items' "value")) with glue " and "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.all(\(%items as lua))"
-parse [not all of %items, not all %items] as: not (all of %items)
-compile [any of %items, any %items] to:
- "(\(join ((% as lua) for all (%items' "value")) with glue " or "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.any(\(%items as lua))"
-parse [none of %items, none %items] as: not (any of %items)
-
-compile [sum of %items, sum %items] to:
- "(\(join ((% as lua) for all (%items' "value")) with glue " + "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.sum(\(%items as lua))"
-compile [product of %items, product %items] to:
- "(\(join ((% as lua) for all (%items' "value")) with glue " * "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.product(\(%items as lua))"