🎉 successful parsing grammar for jobshop data

- now using arpeggio as a parsing lib
This commit is contained in:
Trolli Schmittlauch 2017-06-24 03:17:03 +02:00
parent b89de0e6cb
commit 309664a36a
2 changed files with 22 additions and 0 deletions

View file

@ -1,2 +1,3 @@
mypy
parsimonious
Arpeggio

View file

@ -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)