diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-11 18:51:21 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-11 18:51:21 -0800 |
| commit | e09f05a50cdb699029e8a4d5bafcfaade34157fd (patch) | |
| tree | f216e71f7d7797706145f12349b48cd29d7c45ba /lib/utils2.nom | |
| parent | 06bf76f818382cdd33816073866f3cfd41609597 (diff) | |
Reshuffled all the library code into files that make more sense and
cleaned up some of the library code.
Diffstat (limited to 'lib/utils2.nom')
| -rw-r--r-- | lib/utils2.nom | 63 |
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))" |
