aboutsummaryrefslogtreecommitdiff
path: root/lib/operators.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-07 18:45:27 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-07 18:45:27 -0800
commit568a44ef191e1f4072d379700e3b6f599150a92b (patch)
treec58e74b5f7539a0055d72d8ff40ef6f499aef9ea /lib/operators.nom
parentc92e5fbc81e57ada43f2c17792e500da5b708bee (diff)
Reworking some stuff so that functions only allow expressions to be
return values with either an explicit "return" statement or if they're the only line in the function, and the line is an expression.
Diffstat (limited to 'lib/operators.nom')
-rw-r--r--lib/operators.nom15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/operators.nom b/lib/operators.nom
index 8ea7aad..59a9ad2 100644
--- a/lib/operators.nom
+++ b/lib/operators.nom
@@ -12,8 +12,8 @@ compile [phi, PHI, golden ratio] to: "((1+math.sqrt(5))/2)"
compile [nop, pass] to code: ""
# Ternary operator
-#.. Note: this uses a function instead of (condition and if_expr or else_expr)
- because that breaks if %if_expr is falsey.
+#.. Note: this uses a function instead of "(condition and if_expr or else_expr)"
+ because that breaks if %if_expr is falsey, e.g. "x < 5 and false or 99"
compile [..]
%when_true_expr if %condition else %when_false_expr
%when_true_expr if %condition otherwise %when_false_expr
@@ -27,6 +27,17 @@ compile [..]
return \(%when_false_expr as lua);
end
end)(nomsu, vars)
+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
+..as:
+ %true if (%x == %y) else %false
+
+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
+..as:
+ %true if (%x != %y) else %false
# Indexing:
compile [%obj'%key, %obj's %key, %obj -> %key] to: "(\(%obj as lua))[\(%key as lua)]"