Repository: CrossGL/crosstl

Issue:
BITWISE_XOR : ^

Hints from issue comments:
@anshikavashistha: @samthakur587  Please assign it to me .

Solution patch:
diff --git a/crosstl/src/backend/DirectX/DirectxLexer.py b/crosstl/src/backend/DirectX/DirectxLexer.py
index c9756dfd..be17881f 100644
--- a/crosstl/src/backend/DirectX/DirectxLexer.py
+++ b/crosstl/src/backend/DirectX/DirectxLexer.py
@@ -48,6 +48,7 @@
     ("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 45778a0a..85828c0e 100644
--- a/crosstl/src/backend/DirectX/DirectxParser.py
+++ b/crosstl/src/backend/DirectX/DirectxParser.py
@@ -239,6 +239,7 @@ def parse_variable_declaration_or_assignment(self):
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "BITWISE_XOR",
                 ]:
                     # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
                     op = self.current_token[1]
@@ -257,6 +258,7 @@ def parse_variable_declaration_or_assignment(self):
                 "ASSIGN_OR",
                 "ASSIGN_AND",
                 "SHIFT_LEFT",
+                "BITWISE_XOR",
             ]:
                 # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
                 op = self.current_token[1]
@@ -278,6 +280,7 @@ def parse_variable_declaration_or_assignment(self):
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "BITWISE_XOR",
                 ]:
                     op = self.current_token[1]
                     self.eat(self.current_token[0])
@@ -407,6 +410,7 @@ def parse_assignment(self):
             "ASSIGN_OR",
             "ASSIGN_AND",
             "SHIFT_LEFT",
+            "BITWISE_XOR",
         ]:
             op = self.current_token[1]
             self.eat(self.current_token[0])
@@ -449,6 +453,7 @@ def parse_relational(self):
             "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 b261eef2..b95744c2 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 ba40b854..c5487c51 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;
     }