Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 5, 2024
1 parent 7e62aab commit 2323d60
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
68 changes: 41 additions & 27 deletions crosstl/src/backend/Opengl/OpenglParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ def parse_shader(self, version_node):
self.parse_version_directive()

elif self.current_token[0] in [
"VOID", "FLOAT", "VECTOR", "INT", "UINT", "DOUBLE"
"VOID",
"FLOAT",
"VECTOR",
"INT",
"UINT",
"DOUBLE",
]:
self.skip_comments()
if current_section:
Expand Down Expand Up @@ -319,54 +324,56 @@ def parse_variable(self, type_name):
f"Expected ';' after variable assignment, found: {self.current_token[0]}"
)
elif self.current_token[0] in (
"ASSIGN_ADD",
"ASSIGN_SUB",
"ASSIGN_MUL",
"ASSIGN_DIV",
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND"
"ASSIGN_ADD",
"ASSIGN_SUB",
"ASSIGN_MUL",
"ASSIGN_DIV",
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
):
op = self.current_token[0]
op_name = self.current_token[1]
self.current_token[1]
self.eat(op)
value = self.parse_expression()
if self.current_token[0] == "SEMICOLON":
self.eat("SEMICOLON")
if op == "ASSIGN_ADD":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "PLUS", value)
BinaryOpNode(VariableNode("", name), "PLUS", value),
)
elif op == "ASSIGN_MUL":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "MULTIPLY", value)
BinaryOpNode(VariableNode("", name), "MULTIPLY", value),
)
elif op == "ASSIGN_DIV":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "DIVIDE", value)
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "DIVIDE", value),
)
elif op == "ASSIGN_SUB":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "MINUS", value)
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "MINUS", value),
)
elif op == "ASSIGN_XOR":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "BITWISE_XOR", value)
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "BITWISE_XOR", value),
)
elif op == "ASSIGN_OR":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "BITWISE_OR", value)
VariableNode(type_name, name),
BinaryOpNode(VariableNode("", name), "BITWISE_OR", value),
)
elif op == "ASSIGN_AND":
return AssignmentNode(
VariableNode(type_name, name),
BinaryOpNode(VariableNode(type_name, name), "BITWISE_AND", value)
VariableNode(type_name, name),
BinaryOpNode(
VariableNode(type_name, name), "BITWISE_AND", value
),
)
else:
raise SyntaxError(
Expand All @@ -380,7 +387,12 @@ def parse_variable(self, type_name):
def parse_assignment_or_function_call(self):
type_name = ""
if self.current_token[0] in [
"VECTOR", "FLOAT", "INT", "MATRIX", "DOUBLE", "UINT"
"VECTOR",
"FLOAT",
"INT",
"MATRIX",
"DOUBLE",
"UINT",
]:
type_name = self.current_token[1]
self.eat(self.current_token[0])
Expand Down Expand Up @@ -452,7 +464,12 @@ def parse_body(self):
elif self.current_token[0] == "RETURN":
body.append(self.parse_return())
elif self.current_token[0] in [
"VECTOR", "IDENTIFIER", "FLOAT", "INT", "DOUBLE", "UINT"
"VECTOR",
"IDENTIFIER",
"FLOAT",
"INT",
"DOUBLE",
"UINT",
]:
body.append(self.parse_assignment_or_function_call())
elif self.current_token[0] in ["COMMENT_SINGLE", "COMMENT_MULTI"]:
Expand Down Expand Up @@ -600,9 +617,7 @@ def parse_function_call_or_identifier(self):

def parse_binop(self):
left = self.parse_additive()
while self.current_token[0] in [
"BITWISE_AND", "BITWISE_XOR", "BITWISE_OR"
]:
while self.current_token[0] in ["BITWISE_AND", "BITWISE_XOR", "BITWISE_OR"]:
op = self.current_token[0]
self.eat(op)
right = self.parse_additive()
Expand Down Expand Up @@ -744,4 +759,3 @@ def parse_member_access(self, object):
return self.parse_member_access(MemberAccessNode(object, member))

return MemberAccessNode(object, member)

4 changes: 2 additions & 2 deletions crosstl/src/backend/Opengl/openglCrossglCodegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def map_type(self, vtype):
"int": "int",
"bool": "bool",
"double": "double",
"unsigned int": "uint"
"unsigned int": "uint",
}
return type_map.get(vtype, vtype)

Expand All @@ -305,6 +305,6 @@ def map_operator(self, op):
"OR": "||",
"BITWISE_OR": "|",
"BITWISE_XOR": "^",
"BITWISE_AND": "&"
"BITWISE_AND": "&",
}
return op_map.get(op, op)
2 changes: 1 addition & 1 deletion tests/test_backend/test_opengl/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,4 @@ def uint_test():
float height = noise * 10.0;
vec3 color = vec3(height / 10.0, 1.0 - height / 10.0, 0.0);
}
"""
"""

0 comments on commit 2323d60

Please sign in to comment.