Repository: CrossGL/crosstl

Issue:
BITWISE_OR : |

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 be17881f..b8a23b25 100644
--- a/crosstl/src/backend/DirectX/DirectxLexer.py
+++ b/crosstl/src/backend/DirectX/DirectxLexer.py
@@ -51,6 +51,7 @@
     ("BITWISE_XOR", r"\^"),
     ("AND", r"&&"),
     ("OR", r"\|\|"),
+    ("BITWISE_OR", r"\|"),
     ("DOT", r"\."),
     ("MULTIPLY", r"\*"),
     ("DIVIDE", r"/"),
diff --git a/crosstl/src/backend/DirectX/DirectxParser.py b/crosstl/src/backend/DirectX/DirectxParser.py
index 85828c0e..201a4103 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_OR",
                     "BITWISE_XOR",
                 ]:
                     # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
@@ -258,6 +259,7 @@ def parse_variable_declaration_or_assignment(self):
                 "ASSIGN_OR",
                 "ASSIGN_AND",
                 "SHIFT_LEFT",
+                "BITWISE_OR",
                 "BITWISE_XOR",
             ]:
                 # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
@@ -280,6 +282,7 @@ def parse_variable_declaration_or_assignment(self):
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "BITWISE_OR",
                     "BITWISE_XOR",
                 ]:
                     op = self.current_token[1]
@@ -410,6 +413,7 @@ def parse_assignment(self):
             "ASSIGN_OR",
             "ASSIGN_AND",
             "SHIFT_LEFT",
+            "BITWISE_OR",
             "BITWISE_XOR",
         ]:
             op = self.current_token[1]


Test patch:
diff --git a/tests/test_backend/test_directx/test_codegen.py b/tests/test_backend/test_directx/test_codegen.py
index b95744c2..59294a9e 100644
--- a/tests/test_backend/test_directx/test_codegen.py
+++ b/tests/test_backend/test_directx/test_codegen.py
@@ -404,7 +404,7 @@ def test_else_if_codegen():
         pytest.fail("Else_if statement parsing or code generation not implemented.")
 
 
-def test_assignment_ops_parsing():
+def test_assignment_ops_codegen():
     code = """
     PSOutput PSMain(PSInput input) {
         PSOutput output;
@@ -460,5 +460,31 @@ def test_assignment_ops_parsing():
         pytest.fail("assignment ops parsing or code generation not implemented.")
 
 
+def test_bitwise_ops_codgen():
+    code = """
+        PSOutput PSMain(PSInput input) {
+            PSOutput output;
+            output.out_color = float4(0.0, 0.0, 0.0, 1.0);
+            uint val = 0x01;
+            if (val | 0x02) {
+                // Test case for bitwise OR
+            }
+            uint filterA = 0b0001; // First filter
+            uint filterB = 0b1000; // Second filter
+
+            // Merge both filters
+            uint combinedFilter = filterA | filterB; // combinedFilter becomes 0b1001
+            return output;
+        }
+        """
+    try:
+        tokens = tokenize_code(code)
+        ast = parse_code(tokens)
+        generated_code = generate_code(ast)
+        print(generated_code)
+    except SyntaxError:
+        pytest.fail("bitwise_op parsing or codegen not implemented.")
+
+
 if __name__ == "__main__":
     pytest.main()
diff --git a/tests/test_backend/test_directx/test_lexer.py b/tests/test_backend/test_directx/test_lexer.py
index f9b72c40..296866fb 100644
--- a/tests/test_backend/test_directx/test_lexer.py
+++ b/tests/test_backend/test_directx/test_lexer.py
@@ -157,5 +157,16 @@ def test_assignment_ops_tokenization():
         pytest.fail("assign_op tokenization is not implemented.")
 
 
+def test_bitwise_or_tokenization():
+    code = """
+        uint val = 0x01;
+        val = val | 0x02;
+    """
+    try:
+        tokenize_code(code)
+    except SyntaxError:
+        pytest.fail("bitwise_op tokenization is not implemented.")
+
+
 if __name__ == "__main__":
     pytest.main()
diff --git a/tests/test_backend/test_directx/test_parser.py b/tests/test_backend/test_directx/test_parser.py
index c5487c51..c4bbc89c 100644
--- a/tests/test_backend/test_directx/test_parser.py
+++ b/tests/test_backend/test_directx/test_parser.py
@@ -221,5 +221,29 @@ def test_assignment_ops_parsing():
         pytest.fail("assign_op parsing not implemented.")
 
 
+def test_bitwise_ops_parsing():
+    code = """
+        PSOutput PSMain(PSInput input) {
+            PSOutput output;
+            output.out_color = float4(0.0, 0.0, 0.0, 1.0);
+            uint val = 0x01;
+            if (val | 0x02) {
+                // Test case for bitwise OR
+            }
+            uint filterA = 0b0001; // First filter
+            uint filterB = 0b1000; // Second filter
+
+            // Merge both filters
+            uint combinedFilter = filterA | filterB; // combinedFilter becomes 0b1001
+            return output;
+        }
+        """
+    try:
+        tokens = tokenize_code(code)
+        parse_code(tokens)
+    except SyntaxError:
+        pytest.fail("bitwise_op parsing not implemented.")
+
+
 if __name__ == "__main__":
     pytest.main()