From 568a44ef191e1f4072d379700e3b6f599150a92b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Jan 2018 18:45:27 -0800 Subject: 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. --- lib/operators.nom | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/operators.nom') 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)]" -- cgit v1.2.3