add function for parsing inputdata strings

parser
Trolli Schmittlauch 2017-06-27 23:47:56 +02:00
parent 252e7d6ee0
commit 901472e8b5
2 changed files with 14 additions and 4 deletions

View File

@ -33,14 +33,19 @@ class JobShop1Visitor(JobShopVisitor):
def visit_trim_ws(self, node:arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> None:
return None
def parse_jobshop1_string(inputdata: str) -> JobShopProblem:
"""parse string with jobshop1-formatted data (multiple problem instances)
and return list of JobShopProblem s"""
parse_tree = parser.parse(inputdata)
return arpeggio.visit_parse_tree(parse_tree, JobShop1Visitor())
def parse_jobshop1_file(filename: Union[str, bytes]) -> List[JobShopProblem]:
"""Open file with jobshop1-formatted data (multiple problem instances),
parse it and return list of JobShopProblem s"""
with open(filename) as datafile:
inputdata: str = datafile.read()
parse_tree = parser.parse(inputdata)
return arpeggio.visit_parse_tree(parse_tree, JobShop1Visitor())
return parse_jobshop1_string(inputdata)
def main():

View File

@ -14,14 +14,19 @@ class JobShop2Visitor(JobShopVisitor):
print("returning a", type(problem))
return problem
def parse_jobshop2_string(inputdata: str) -> JobShopProblem:
"""parse string of jobshop2-formatted data (single problem instance, no name & description)
and return JobShopProblem"""
parse_tree = parser.parse(inputdata)
return arpeggio.visit_parse_tree(parse_tree, JobShop2Visitor())
def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem:
"""Open file with jobshop2-formatted data (single problem instance, no name & description),
parse it and return JobShopProblem"""
with open(filename) as datafile:
inputdata: str = datafile.read()
parse_tree = parser.parse(inputdata)
return arpeggio.visit_parse_tree(parse_tree, JobShop2Visitor())
return parse_jobshop2_string(inputdata)
def main():
print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13')))