Commits

Anonymous committed 63c0b70

Implement is [not] operator, without chaining

Comments (0)

Files changed (3)

Grammar/Actions.nqp

 
 
 method is_test($/) {
-    make $($<comparison>[0]);
+    if +$<comparison> > 1 {
+        my $pirop;
+        if +$<not> {
+            $pirop := 'isntsame IPP';
+        } else {
+            $pirop := 'issame';
+        }
+        
+        make PAST::Op.new( $($<comparison>[0]),
+                           $($<comparison>[1]),
+                           :pirop($pirop),
+                           :node($/) );
+    } else {
+        make $($<comparison>[0]);
+    }
 }
 
 method comparison($/, $key) {

Grammar/Grammar.pg

 }
 
 rule is_test {
-    <comparison> [ 'is' ['not']? <comparison> ]*
+    # XXX allow chaining (X is X is X)
+    <comparison> [ 'is' [$<not>='not']? <comparison> ]?
     {*}
 }
 

Lib/test/parrot/op-cmp.py

 
 print('test: 2 greater than 1, greater than 0')
 if 2 > 1 > 0: print('success: 2 greater than 1, greater than 0')
+
+print('test: is operator - compare int with self')
+a = 1000
+if a is a:
+    print('success: is operator - compare int with self')
+else:
+    print('failure: is operator - compare int with self')
+
+print('test: is operator - compare 2 ints')
+a = 1000
+b = 1000
+if not (a is b):
+    print('success: is operator - compare 2 ints')
+else:
+    print('failure: is operator - compare 2 ints')
+
+print('test: is not operator - compare int with self')
+a = 1000
+if not (a is not a):
+    print('success: is not operator - compare int with self')
+else:
+    print('failure: is not operator - compare int with self')
+
+print('test: is not operator - compare 2 ints')
+a = 1000
+b = 1000
+if a is not b:
+    print('success: is not operator - compare 2 ints')
+else:
+    print('failure: is not operator - compare 2 ints')