Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittests for visitor #6

Merged
merged 6 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions pfdl_scheduler/parser/pfdl_tree_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,16 @@ def visitCall_output(self, ctx: PFDLParser.Call_outputContext) -> Dict[str, Unio
def visitParameter(self, ctx: PFDLParser.ParameterContext) -> Union[str, List[str]]:
if ctx.STARTS_WITH_LOWER_C_STR():
return ctx.STARTS_WITH_LOWER_C_STR().getText()
if ctx.attribute_access():
return self.visitAttribute_access(ctx.attribute_access())
return self.visitValue(ctx.value())
return self.visitAttribute_access(ctx.attribute_access())

def visitStruct_initialization(self, ctx: PFDLParser.Struct_initializationContext) -> Struct:
json_object_ctx = ctx.json_object()
json_string = self.visitJson_object(json_object_ctx)
json_string = ctx.json_object().getText()

struct = Struct.from_json(json_string, self.error_handler, ctx.json_object())
struct.name = ctx.STARTS_WITH_UPPER_C_STR().getText()
struct.context = ctx
return struct

def visitJson_object(self, ctx: PFDLParser.Json_objectContext) -> str:
return ctx.getText()

def visitTask_call(self, ctx: PFDLParser.Task_callContext) -> TaskCall:
task_call = TaskCall()
task_call.name = ctx.STARTS_WITH_LOWER_C_STR().getText()
Expand All @@ -246,6 +240,7 @@ def visitTask_call(self, ctx: PFDLParser.Task_callContext) -> TaskCall:

def visitParallel(self, ctx: PFDLParser.ParallelContext) -> Parallel:
parallel = Parallel()
parallel.context = ctx
for task_call_context in ctx.task_call():
task_call = self.visitTask_call(task_call_context)
parallel.task_calls.append(task_call)
Expand Down Expand Up @@ -317,11 +312,14 @@ def visitVariable_definition(
array = Array()
array.type_of_elements = variable_type
array.context = ctx.array()
array.length = self.visitArray(ctx.array())
if not isinstance(array.length, int):
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

variable_type = array

return (identifier, variable_type)
Expand Down
Loading