Repository: CrossGL/crosstl

Issue:
BITWISE_XOR : ^

Discussion:
anshikavashistha: @samthakur587 PTAL

Patch:
diff --git a/crosstl/src/backend/DirectX/DirectxLexer.py b/crosstl/src/backend/DirectX/DirectxLexer.py
index c9756df..be17881 100644
--- a/crosstl/src/backend/DirectX/DirectxLexer.py
+++ b/crosstl/src/backend/DirectX/DirectxLexer.py
@@ -48,6 +48,7 @@ TOKENS = [
     ("ASSIGN_XOR", r"\^="),
     ("ASSIGN_OR", r"\|="),
     ("ASSIGN_AND", r"\&="),
+    ("BITWISE_XOR", r"\^"),
     ("AND", r"&&"),
     ("OR", r"\|\|"),
     ("DOT", r"\."),
diff --git a/crosstl/src/backend/DirectX/DirectxParser.py b/crosstl/src/backend/DirectX/DirectxParser.py
index 45778a0..85828c0 100644
--- a/crosstl/src/backend/DirectX/DirectxParser.py
+++ b/crosstl/src/backend/DirectX/DirectxParser.py
@@ -239,6 +239,7 @@ class HLSLParser:
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "BITWISE_XOR",
                 ]:
                     # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
                     op = self.current_token[1]
@@ -257,6 +258,7 @@ class HLSLParser:
                 "ASSIGN_OR",
                 "ASSIGN_AND",
                 "SHIFT_LEFT",
+                "BITWISE_XOR",
             ]:
                 # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
                 op = self.current_token[1]
@@ -278,6 +280,7 @@ class HLSLParser:
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "BITWISE_XOR",
                 ]:
                     op = self.current_token[1]
                     self.eat(self.current_token[0])
@@ -407,6 +410,7 @@ class HLSLParser:
             "ASSIGN_OR",
             "ASSIGN_AND",
             "SHIFT_LEFT",
+            "BITWISE_XOR",
         ]:
             op = self.current_token[1]
             self.eat(self.current_token[0])
@@ -449,6 +453,7 @@ class HLSLParser:
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",
+            "BITWISE_XOR",
         ]:
             op = self.current_token[1]
             self.eat(self.current_token[0])


Test patch:
diff --git a/tests/test_backend/test_directx/test_codegen.py b/tests/test_backend/test_directx/test_codegen.py
index b261eef..b95744c 100644
--- a/tests/test_backend/test_directx/test_codegen.py
+++ b/tests/test_backend/test_directx/test_codegen.py
@@ -438,6 +438,15 @@ def test_assignment_ops_parsing():
             output.redValue &= 0x3;
         }
 
+        // Testing BITWISE_XOR (^) operator on some condition
+        if (input.in_position.r == 0.5) {
+            uint redValue = asuint(output.out_color.r);
+            output.redValue ^ 0x1;  
+            // BITWISE_XOR operation
+            output.out_color.r = asfloat(redValue);
+        }
+
+
 
         return output;
     }
diff --git a/tests/test_backend/test_directx/test_parser.py b/tests/test_backend/test_directx/test_parser.py
index ba40b85..c5487c5 100644
--- a/tests/test_backend/test_directx/test_parser.py
+++ b/tests/test_backend/test_directx/test_parser.py
@@ -202,6 +202,14 @@ def test_assignment_ops_parsing():
             output.redValue &= 0x3;
         }
 
+        // Testing BITWISE_XOR (^) operator on some condition
+        if (input.in_position.r == 0.5) {
+            uint redValue = asuint(output.out_color.r);
+            output.redValue ^ 0x1;  // BITWISE_XOR operation
+            output.out_color.r = asfloat(redValue);
+        }
+
+
 
         return output;
     }