diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-10 20:45:03 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-10 20:45:03 -0800 |
| commit | 53a9d4eae888d2b09c68fcd5dc14ae51f5d07c31 (patch) | |
| tree | 87c21e8c2400ae5a51200412329e6b32892fe7ac /lib/utils.nom | |
| parent | 09b64e034147969a3621c4c46075741a8034c423 (diff) | |
Pretty much mostly working.
Diffstat (limited to 'lib/utils.nom')
| -rw-r--r-- | lib/utils.nom | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/utils.nom b/lib/utils.nom index ddaac8d..ce6dc9d 100644 --- a/lib/utils.nom +++ b/lib/utils.nom @@ -7,7 +7,7 @@ rule [error %msg] =: nomsu "error"[%msg] compile [assert %condition %msg] to code: ".." if not (\(%condition as lua)) then - nomsu:error(\(%msg as lua)) + nomsu:error(\(%msg as lua)); end parse [assert %condition] as: assert %condition (nil) @@ -80,19 +80,17 @@ compile [min of %items, smallest of %items, lowest of %items] to: compile [max of %items, biggest of %items, largest of %items, highest of %items] to: "nomsu.utils.max(\(%items as lua))" compile [min of %items by %value_expr] to: ".." - nomsu.utils.min(\(%items as lua), function(item) - local vars = setmetatable({['']=item}, {__index=vars}) + nomsu.utils.min(\(%items as lua), function(\(\% as lua)) return \(%value_expr as lua) end) compile [max of %items by %value_expr] to: ".." - nomsu.utils.max(\(%items as lua), function(item) - local vars = setmetatable({['']=item}, {__index=vars}) + nomsu.utils.max(\(%items as lua), function(\(\% as lua)) return \(%value_expr as lua) end) compile [sort %items] to: "table.sort(\(%items as lua))" -rule [sort %items by %key] =: =lua ".." - nomsu.utils.sort(\%items, function(x) - return (\%key)(nomsu, {['']=x}); +compile [sort %items by %key_expr] to: ".." + nomsu.utils.sort(\(%items as lua), function(\(\% as lua)) + return \(%key_expr as lua); end) # String utilities |
