aboutsummaryrefslogtreecommitdiff
path: root/lib/utils2.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-07 18:03:37 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-07 18:03:37 -0800
commitc92e5fbc81e57ada43f2c17792e500da5b708bee (patch)
tree8f89f2c0ab21de3fe6110c84ee980e0920d18fb4 /lib/utils2.nom
parentb1c6354464ab2c9f8f09217815a11317cc068cec (diff)
Some overhaul of binary operators so that arbitrary math patterns work
fine.
Diffstat (limited to 'lib/utils2.nom')
-rw-r--r--lib/utils2.nom25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/utils2.nom b/lib/utils2.nom
index 07ff008..89a0767 100644
--- a/lib/utils2.nom
+++ b/lib/utils2.nom
@@ -49,3 +49,28 @@ compile [with %assignments %action] to code:
end
parse [with %thing = %value %action] as: with [%thing = %value] %action
+# Any/all/none
+compile [all of %items, all %items] to:
+ if (%items' "type") == "List":
+ "(\(join ((% as lua) for all (%items' "value")) with glue " and "))"
+ ..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:
+ if (%items' "type") == "List":
+ "(\(join ((% as lua) for all (%items' "value")) with glue " or "))"
+ ..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:
+ if (%items' "type") == "List":
+ "(\(join ((% as lua) for all (%items' "value")) with glue " + "))"
+ ..else:
+ "nomsu.utils.sum(\(%items as lua))"
+compile [product of %items, product %items] to:
+ if (%items' "type") == "List":
+ "(\(join ((% as lua) for all (%items' "value")) with glue " * "))"
+ ..else:
+ "nomsu.utils.product(\(%items as lua))"