🎉 successful parsing grammar for jobshop data
- now using arpeggio as a parsing lib
This commit is contained in:
parent
b89de0e6cb
commit
309664a36a
|
@ -1,2 +1,3 @@
|
|||
mypy
|
||||
parsimonious
|
||||
Arpeggio
|
||||
|
|
21
src/JobShopParser/jobshop2_parser.py
Normal file
21
src/JobShopParser/jobshop2_parser.py
Normal 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)
|
Loading…
Reference in a new issue