aboutsummaryrefslogtreecommitdiff
path: root/lib/operators.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-11 01:03:52 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-11 01:04:17 -0800
commitc0333ca31532f14ec8ebd841a5f68b2f35e9cc80 (patch)
treecca1698b04eec2afb6adc7de55860caf12e90dca /lib/operators.nom
parent53a9d4eae888d2b09c68fcd5dc14ae51f5d07c31 (diff)
Overhaul of error reporting and removing nomsu:call(stub, line_no, ...) in favor of nomsu.defs[stub].fn(...)
Diffstat (limited to 'lib/operators.nom')
-rw-r--r--lib/operators.nom22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/operators.nom b/lib/operators.nom
index 1670191..7eada51 100644
--- a/lib/operators.nom
+++ b/lib/operators.nom
@@ -19,14 +19,24 @@ compile [..]
%when_true_expr if %condition otherwise %when_false_expr
%when_false_expr unless %condition else %when_true_expr
%when_false_expr unless %condition then %when_true_expr
-..to: ".."
- (function(nomsu, condition)
- if condition then
- return \(%when_true_expr as lua);
+..to:
+ lua> ".."
+ local condition = nomsu:tree_to_lua(\%condition).expr;
+ local when_true = nomsu:tree_to_lua(\%when_true_expr).expr;
+ local when_false = nomsu:tree_to_lua(\%when_false_expr).expr;
+ local safe = {String=true, List=true, Dict=true, Number=true};
+ if safe[\%when_true_expr.type] then
+ return "("..condition.." and "..when_true.." or "..when_false..")";
else
- return \(%when_false_expr as lua);
+ return ([[
+ (function(nomsu)
+ if %s then
+ return %s;
+ else
+ return %s;
+ end
+ end)(nomsu)]]):format(condition, when_true, when_false);
end
- end)(nomsu, \(%condition as lua))
parse [..]
%true if %x == %y else %false, %true if %x == %y otherwise %false
%false unless %x == %y else %true, %false unless %x == %y otherwise %true