From 5bd0be95a0ff3d979bc7c2c4522ebb0048949fc6 Mon Sep 17 00:00:00 2001 From: Oliver Stolz Date: Wed, 10 Apr 2024 16:31:03 +0200 Subject: [PATCH] Split method - Enable reusing parts of the method when multiple types per variable are allowed --- pfdl_scheduler/parser/pfdl_tree_visitor.py | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pfdl_scheduler/parser/pfdl_tree_visitor.py b/pfdl_scheduler/parser/pfdl_tree_visitor.py index 2c7f5ec..a27ad46 100644 --- a/pfdl_scheduler/parser/pfdl_tree_visitor.py +++ b/pfdl_scheduler/parser/pfdl_tree_visitor.py @@ -313,17 +313,7 @@ def visitVariable_definition( variable_type = self.visitPrimitive(ctx.primitive()) if ctx.array(): - array = Array() - array.type_of_elements = variable_type - array.context = ctx.array() - length = self.visitArray(ctx.array()) - if not isinstance(length, int): - self.error_handler.print_error( - "Array length has to be specified by an integer", syntax_error=True - ) - else: - array.length = length - + array = self.initializeArray(ctx.array(), variable_type) variable_type = array return (identifier, variable_type) @@ -331,6 +321,20 @@ def visitVariable_definition( def visitPrimitive(self, ctx: PFDLParser.PrimitiveContext): return ctx.getText() + def initializeArray(self, array_ctx: PFDLParser.ArrayContext, variable_type: str) -> Array: + array = Array() + array.type_of_elements = variable_type + array.context = array_ctx + length = self.visitArray(array_ctx) + if not isinstance(length, int): + self.error_handler.print_error( + "Array length has to be specified by an integer", syntax_error=True + ) + else: + array.length = length + + return array + def visitAttribute_access(self, ctx: PFDLParser.Attribute_accessContext) -> List[str]: access_list = []