diff --git a/src/JobShopParser/__init__.py b/src/JobShopParser/__init__.py index 51df1c2..40615f6 100644 --- a/src/JobShopParser/__init__.py +++ b/src/JobShopParser/__init__.py @@ -83,8 +83,13 @@ class JobShopVisitor(arpeggio.PTNodeVisitor): def visit_problem_data(self, node: arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> JobShopProblem: if self.debug: print("problem_data\nchildren:", children) + # filter out newlines or other strings cleaned_data = list(filter(lambda x: type(x) is not str, children)) problem_data: List[List[Tuple(int, int)]] = [ cleaned_data[i] for i in range(2, len(cleaned_data))] - return JobShopProblem(children[0], children[1], problem_data) + problem = JobShopProblem(children[0], children[1], problem_data) + if self.debug: + print("\nreturning a", type(problem), "\n") + print("problem_data:", problem_data) + return problem diff --git a/src/JobShopParser/jobshop2_parser.py b/src/JobShopParser/jobshop2_parser.py index dc49898..43b6d30 100644 --- a/src/JobShopParser/jobshop2_parser.py +++ b/src/JobShopParser/jobshop2_parser.py @@ -5,7 +5,14 @@ from typing import List, Tuple, Sequence, Optional, Union from . import grammar, JobShopVisitor, JobShopProblem class JobShop2Visitor(JobShopVisitor): - pass + + def visit_job_shop2(self, node: arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> JobShopProblem: + if self.debug: + print("job_shop2:\nchildren:", children) + problem = children[0] + if self.debug: + print("returning a", type(problem)) + return problem def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem: """Open file with jobshop2-formatted data (single problem instance, no name & description), @@ -17,7 +24,7 @@ def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem: return arpeggio.visit_parse_tree(parse_tree, JobShop2Visitor()) def main(): - print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13').problem_data)) + print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13'))) parser = ParserPEG(grammar, "job_shop2", skipws=False)