grammar now matches Jobshop1 without prefix
- grammar matches, but result not yet evaluated
This commit is contained in:
parent
309664a36a
commit
0d1a38caa9
2245
inputdata/jobshop1_noprefix.txt
Normal file
2245
inputdata/jobshop1_noprefix.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,22 +1,30 @@
|
|||
from parsimonious.grammar import Grammar
|
||||
from arpeggio.cleanpeg import ParserPEG
|
||||
|
||||
grammar = Grammar(
|
||||
r"""
|
||||
grammar = """
|
||||
start = skip_preface
|
||||
skip_preface = instance_list / (~"."s skip_preface)
|
||||
eol = "\n" / "\r\n"
|
||||
_ = " "
|
||||
instance_list = problem_instance (sep_line problem_instance eol)* eof
|
||||
problem_instance = strip_whitespace "instance" _ instance_name eol eol sep_line description eol job_data
|
||||
description = ~".*"
|
||||
instance_name = ~"\w"
|
||||
sep_line = strip_whitespace plus_line strip_whitespace eol
|
||||
plus_line = ~"\+\+\++"
|
||||
eof = strip_whitespace plus_line " EOF " plus_line strip_whitespace
|
||||
strip_whitespace = ~"[\t ]*"
|
||||
job_data = ~"[ \r\n0-9]*"s
|
||||
""")
|
||||
skip_preface = instance_list / (r"." skip_preface)
|
||||
instance_list = problem_instance (sep_line trim_ws eol problem_instance eol?)* eof_sep
|
||||
problem_instance = trim_ws "instance" ' ' instance_name trim_ws eol trim_ws eol sep_line description eol problem_data
|
||||
description = r"[^\n]*"
|
||||
instance_name = r"\w+"
|
||||
sep_line = trim_ws plus_line trim_ws eol
|
||||
plus_line = r"\+\+\++"
|
||||
eof_sep = trim_ws plus_line " EOF " plus_line trim_ws eol* EOF
|
||||
|
||||
with open("./inputdata/jobshop1.txt") as datafile:
|
||||
job_shop2 = problem_data EOF
|
||||
problem_data = trim_ws num_jobs ' ' num_machines eol job_data+
|
||||
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, "start", skipws=False,debug=True)
|
||||
|
||||
with open("./inputdata/jobshop1_noprefix.txt") as datafile:
|
||||
inputdata : str = datafile.read()
|
||||
print(grammar.parse(inputdata))
|
||||
parse_tree = parser.parse(inputdata)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from arpeggio.cleanpeg import ParserPEG
|
||||
|
||||
grammar = """
|
||||
problem_data = trim_ws num_jobs ' ' num_machines eol job_data+ EOF
|
||||
job_shop2 = problem_data EOF
|
||||
problem_data = trim_ws num_jobs ' ' num_machines eol job_data+
|
||||
trim_ws = r'[ \t]*'
|
||||
eol = "\n" / "\r\n"
|
||||
nonneg_num = r'\d+'
|
||||
|
@ -12,7 +13,7 @@ duration = nonneg_num
|
|||
job_data = ' '* machine ' '+ duration (' '+ machine ' '+ duration)* trim_ws eol
|
||||
"""
|
||||
|
||||
parser = ParserPEG(grammar, "problem_data", skipws=False)
|
||||
parser = ParserPEG(grammar, "problem_data", skipws=False,debug=True)
|
||||
|
||||
with open('./inputdata/jobshop2/ta13') as jobdatafile:
|
||||
jobdata : str = jobdatafile.read()
|
||||
|
|
Loading…
Reference in a new issue