Repository: CrossGL/crosstl
Pull request #102 (2024-08-27 17:49:29)

Added Parsing for Bitwise Shift Right and Bitwise Shift Right Token
##PR Description

Updated parser.py to handle Bitwise Shift Right and Bitwise Shift Right Token.
Added Testcases to validate the parser.

###Related Issue
This PR addresses and closes the following Issues:
-Closes [#74](https://github.com/CrossGL/crosstl/issues/74) Add Parsing for Bitwise Shift Left Token
-Closes [#75](https://github.com/CrossGL/crosstl/issues/75) Add Parsing for Bitwise Shift Right Token


### Checklist
- [x] Have you added the necessary tests?
- [x] Only modified the files mentioned in the related issue(s)?
- [x] Are all tests passing?




samthakur587: can you please resolve the merge conflicts 😄 

Patch:
diff --git a/crosstl/src/translator/parser.py b/crosstl/src/translator/parser.py
index 51ad041..bf5862c 100644
--- a/crosstl/src/translator/parser.py
+++ b/crosstl/src/translator/parser.py
@@ -625,6 +625,8 @@ class Parser:
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",
+            "BITWISE_SHIFT_RIGHT",
+            "BITWISE_SHIFT_LEFT",
         ]:
             return self.parse_assignment(name)
         elif self.current_token[0] == "INCREMENT":
@@ -679,6 +681,8 @@ class Parser:
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",
+            "BITWISE_SHIFT_RIGHT",
+            "BITWISE_SHIFT_LEFT",
         ]:
             op = self.current_token[1]
             self.eat(self.current_token[0])
@@ -707,6 +711,8 @@ class Parser:
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",
+            "BITWISE_SHIFT_RIGHT",
+            "BITWISE_SHIFT_LEFT",
             "EQUAL",
         ):
             op = self.current_token[0]
@@ -755,6 +761,8 @@ class Parser:
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",
+            "BITWISE_SHIFT_RIGHT",
+            "BITWISE_SHIFT_LEFT",
         ]:
             op = self.current_token[0]
             op_name = self.current_token[1]
@@ -913,6 +921,8 @@ class Parser:
             "ASSIGN_SUB",
             "ASSIGN_MUL",
             "ASSIGN_DIV",
+            "BITWISE_SHIFT_RIGHT",
+            "BITWISE_SHIFT_LEFT",
         ]:
             op = self.current_token[0]
             self.eat(op)


Test patch:
diff --git a/tests/test_translator/test_parser.py b/tests/test_translator/test_parser.py
index a12a3ad..dd65d7f 100644
--- a/tests/test_translator/test_parser.py
+++ b/tests/test_translator/test_parser.py
@@ -281,3 +281,30 @@ def test_var_assignment():
         parse_code(tokens)
     except SyntaxError:
         pytest.fail("Variable assignment parsing not implemented.")
+
+
+def test_bitwise_operators():
+    code = """
+        shader LightControl {
+        vertex {
+            input vec3 position;
+            output int isLightOn;
+            void main() {        
+                    isLightOn = 2 >> 1;
+            }
+        }
+        fragment {
+            input int isLightOn;
+            output vec4 fragColor;
+            void main() {
+                isLightOn = isLightOn << 1;
+            }
+        }
+    }
+
+    """
+    try:
+        tokens = tokenize_code(code)
+        parse_code(tokens)
+    except SyntaxError:
+        pytest.fail("Bitwise Shift not working")