Commits

Anonymous committed afeb0c4

Issue 7: Implement conditional expressions. isop44++

Comments (0)

Files changed (2)

Grammar/Actions.nqp

 
 
 method expression($/, $key) {
-    ## XXX incomplete.
     if $key eq 'lambda_form' {
         make $( $<lambda_form> );
     }
     else {
-        make $( $<or_test>[0] );
+        my $past;
+        
+        if ( +$<or_test> > 1 ) {
+            $past := PAST::Op.new( $( $<or_test>[1] ),
+                                   $( $<or_test>[0] ),
+                                   $( $<test>[0] ),
+                                   :pasttype('if'),
+                                   :node( $/ )
+                                   );
+        } else {
+            $past := $( $<or_test>[0] );
+        }
+        
+        make $past;
     }
 }
 

Lib/test/parrot/op-boolean.py

 print('xfail: double NOT [')
 print('fix double nots')
 print(']')
+
+print('test: conditional expressions')
+if 5 == (5 if 1 else 8) and 8 == (5 if 0 else 8):
+    print('success: conditional expressions')
+else:
+    print('failure: conditional expressions')