From 309664a36a6c52df6995830f9bea2fbe39282e9d Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Sat, 24 Jun 2017 03:17:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20successful=20parsing=20grammar?= =?UTF-8?q?=20for=20jobshop=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - now using arpeggio as a parsing lib --- requirements.txt | 1 + src/JobShopParser/jobshop2_parser.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/JobShopParser/jobshop2_parser.py diff --git a/requirements.txt b/requirements.txt index 1a2f7b1..a1e3d13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ mypy parsimonious +Arpeggio diff --git a/src/JobShopParser/jobshop2_parser.py b/src/JobShopParser/jobshop2_parser.py new file mode 100644 index 0000000..91ba803 --- /dev/null +++ b/src/JobShopParser/jobshop2_parser.py @@ -0,0 +1,21 @@ +from arpeggio.cleanpeg import ParserPEG + +grammar = """ +problem_data = trim_ws num_jobs ' ' num_machines eol job_data+ EOF +trim_ws = r'[ \t]*' +eol = "\n" / "\r\n" +nonneg_num = r'\d+' +num_jobs = nonneg_num +num_machines = nonneg_num +machine = nonneg_num +duration = nonneg_num +job_data = ' '* machine ' '+ duration (' '+ machine ' '+ duration)* trim_ws eol +""" + +parser = ParserPEG(grammar, "problem_data", skipws=False) + +with open('./inputdata/jobshop2/ta13') as jobdatafile: + jobdata : str = jobdatafile.read() + print("zu parsender String:\n\v\v", jobdata) + parse_tree = parser.parse(jobdata) + print(parse_tree)