Repository: CrossGL/crosstl

Issue:
SHIFT_LEFT : <<

Discussion:
anshikavashistha: @samthakur587 PTAL

Patch:
diff --git a/crosstl/src/backend/DirectX/DirectxLexer.py b/crosstl/src/backend/DirectX/DirectxLexer.py
index 41c8a78..c9756df 100644
--- a/crosstl/src/backend/DirectX/DirectxLexer.py
+++ b/crosstl/src/backend/DirectX/DirectxLexer.py
@@ -34,6 +34,7 @@ TOKENS = [
     ("COMMA", r","),
     ("COLON", r":"),
     ("QUESTION", r"\?"),
+    ("SHIFT_LEFT", r"<<"),
     ("LESS_EQUAL", r"<="),
     ("GREATER_EQUAL", r">="),
     ("LESS_THAN", r"<"),
diff --git a/crosstl/src/backend/DirectX/DirectxParser.py b/crosstl/src/backend/DirectX/DirectxParser.py
index 1d70563..45778a0 100644
--- a/crosstl/src/backend/DirectX/DirectxParser.py
+++ b/crosstl/src/backend/DirectX/DirectxParser.py
@@ -238,6 +238,7 @@ class HLSLParser:
                     "ASSIGN_XOR",
                     "ASSIGN_OR",
                     "ASSIGN_AND",
+                    "SHIFT_LEFT",
                 ]:
                     # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
                     op = self.current_token[1]
@@ -255,6 +256,7 @@ class HLSLParser:
                 "ASSIGN_XOR",
                 "ASSIGN_OR",
                 "ASSIGN_AND",
+                "SHIFT_LEFT",
             ]:
                 # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
                 op = self.current_token[1]
@@ -275,6 +277,7 @@ class HLSLParser:
                     "ASSIGN_XOR",
                     "ASSIGN_OR",
                     "ASSIGN_AND",
+                    "SHIFT_LEFT",
                 ]:
                     op = self.current_token[1]
                     self.eat(self.current_token[0])
@@ -403,6 +406,7 @@ class HLSLParser:
             "ASSIGN_XOR",
             "ASSIGN_OR",
             "ASSIGN_AND",
+            "SHIFT_LEFT",
         ]:
             op = self.current_token[1]
             self.eat(self.current_token[0])
@@ -441,6 +445,7 @@ class HLSLParser:
         left = self.parse_additive()
         while self.current_token[0] in [
             "LESS_THAN",
+            "SHIFT_LEFT",
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",


Test patch:
diff --git a/tests/test_backend/test_directx/test_codegen.py b/tests/test_backend/test_directx/test_codegen.py
index 65e9f48..b261eef 100644
--- a/tests/test_backend/test_directx/test_codegen.py
+++ b/tests/test_backend/test_directx/test_codegen.py
@@ -426,17 +426,19 @@ def test_assignment_ops_parsing():
             out_color /= 2.0;
         }
 
+        // Testing SHIFT_LEFT (<<) operator on some condition
         if (input.in_position.r == 0.5) {
             uint redValue = asuint(output.out_color.r);
             output.redValue ^= 0x1;
             output.out_color.r = asfloat(redValue);
 
             output.redValue |= 0x2;
-
+            // Applying shift left operation
+            output.redValue << 1; // Shift left by 1
             output.redValue &= 0x3;
-
         }
 
+
         return output;
     }
     """
diff --git a/tests/test_backend/test_directx/test_lexer.py b/tests/test_backend/test_directx/test_lexer.py
index 76ba0bc..f9b72c4 100644
--- a/tests/test_backend/test_directx/test_lexer.py
+++ b/tests/test_backend/test_directx/test_lexer.py
@@ -133,16 +133,21 @@ def test_assignment_ops_tokenization():
             output.out_color /= 2.0;
         }
 
+        // Testing SHIFT_LEFT (<<) operator on some condition
         if (input.in_position.r == 0.5) {
             uint redValue = asuint(output.out_color.r);
-            redValue ^= 0x1;
+            output.redValue ^= 0x1;
             output.out_color.r = asfloat(redValue);
+            output.redValue |= 0x2;
 
+            // Applying shift left operation
+            output.redValue << 1; // Shift left by 1
             redValue |= 0x2;
 
             redValue &= 0x3;
         }
 
+
         return output;
     }
     """
diff --git a/tests/test_backend/test_directx/test_parser.py b/tests/test_backend/test_directx/test_parser.py
index d1c2b7a..ba40b85 100644
--- a/tests/test_backend/test_directx/test_parser.py
+++ b/tests/test_backend/test_directx/test_parser.py
@@ -190,16 +190,19 @@ def test_assignment_ops_parsing():
             out_color /= 2.0;
         }
 
+        // Testing SHIFT_LEFT (<<) operator on some condition
         if (input.in_position.r == 0.5) {
             uint redValue = asuint(output.out_color.r);
             output.redValue ^= 0x1;
             output.out_color.r = asfloat(redValue);
 
             output.redValue |= 0x2;
-
+            // Applying shift left operation
+            output.redValue << 1; // Shift left by 1
             output.redValue &= 0x3;
         }
 
+
         return output;
     }
     """