aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-29 15:14:39 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-29 15:14:50 -0800
commit27c80248889ff68aa51420f7c9b9dc07957525c5 (patch)
treee51f2528449f03e65f4452fc5cc34be0044d5539 /lib
parentf0446a27c9cf489d12b291ef19da185832c4830a (diff)
Added numeric-for list comprehension
Diffstat (limited to 'lib')
-rw-r--r--lib/collections.nom23
-rw-r--r--lib/object.nom (renamed from lib/class.nom)0
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/collections.nom b/lib/collections.nom
index ac1b019..a2ee0cc 100644
--- a/lib/collections.nom
+++ b/lib/collections.nom
@@ -75,6 +75,29 @@ immediately
end)()
parse [%expression for all %iterable] as: %expression for % in %iterable
+ compile [..]
+ %expression for %index from %start to %stop via %step
+ %expression for %index from %start to %stop by %step
+ ..to
+ assume ((%index's "type") is "Var") or barf ".."
+ List comprehension has the wrong type for the loop variable. Expected Var, but got: \(%index's "type")
+ return {..}
+ expr:".."
+ (function()
+ local comprehension = {};
+ for \(%index as lua expr)=\(%start as lua expr),\(%stop as lua expr),\(%step as lua expr) do
+ comprehension[\(%index as lua expr)] = \(%expression as lua expr);
+ end
+ return comprehension;
+ end)()
+ parse [%expression for all ] as: %expression for % in %iterable
+ parse [%expression for %var from %start to %stop] as: %expression for %var from %start to %stop via 1
+ parse [..]
+ %expression for all %start to %stop by %step
+ %expression for all %start to %stop via %step
+ ..as: %expression for % from %start to %stop via %step
+ parse [%expression for all %start to %stop] as: %expression for all %start to %stop via 1
+
compile [%expression for %key = %value in %iterable] to
assume ((%key's "type") is "Var") or barf ".."
List comprehension has the wrong type for the key loop variable. Expected Var, but got: \(%key's "type")
diff --git a/lib/class.nom b/lib/object.nom
index b7506f3..b7506f3 100644
--- a/lib/class.nom
+++ b/lib/object.nom