From e09f05a50cdb699029e8a4d5bafcfaade34157fd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 11 Jan 2018 18:51:21 -0800 Subject: Reshuffled all the library code into files that make more sense and cleaned up some of the library code. --- lib/utils2.nom | 63 ---------------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 lib/utils2.nom (limited to 'lib/utils2.nom') 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))" -- cgit v1.2.3