26 lines
815 B
Python
26 lines
815 B
Python
import arpeggio
|
|
from arpeggio.cleanpeg import ParserPEG
|
|
from typing import List, Tuple, Sequence, Optional, Union
|
|
|
|
from common import grammar, JobShopVisitor, JobShopProblem
|
|
|
|
class JobShop2Visitor(JobShopVisitor):
|
|
pass
|
|
|
|
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())
|
|
|
|
def main():
|
|
print(parse_jobshop2_file('./inputdata/jobshop2/ta13').problem_data)
|
|
|
|
parser = ParserPEG(grammar, "problem_data", skipws=False)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|