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(
|
grammar = """
|
||||||
r"""
|
|
||||||
start = skip_preface
|
start = skip_preface
|
||||||
skip_preface = instance_list / (~"."s skip_preface)
|
skip_preface = instance_list / (r"." skip_preface)
|
||||||
eol = "\n" / "\r\n"
|
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
|
||||||
instance_list = problem_instance (sep_line problem_instance eol)* eof
|
description = r"[^\n]*"
|
||||||
problem_instance = strip_whitespace "instance" _ instance_name eol eol sep_line description eol job_data
|
instance_name = r"\w+"
|
||||||
description = ~".*"
|
sep_line = trim_ws plus_line trim_ws eol
|
||||||
instance_name = ~"\w"
|
plus_line = r"\+\+\++"
|
||||||
sep_line = strip_whitespace plus_line strip_whitespace eol
|
eof_sep = trim_ws plus_line " EOF " plus_line trim_ws eol* EOF
|
||||||
plus_line = ~"\+\+\++"
|
|
||||||
eof = strip_whitespace plus_line " EOF " plus_line strip_whitespace
|
|
||||||
strip_whitespace = ~"[\t ]*"
|
|
||||||
job_data = ~"[ \r\n0-9]*"s
|
|
||||||
""")
|
|
||||||
|
|
||||||
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()
|
inputdata : str = datafile.read()
|
||||||
print(grammar.parse(inputdata))
|
parse_tree = parser.parse(inputdata)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from arpeggio.cleanpeg import ParserPEG
|
from arpeggio.cleanpeg import ParserPEG
|
||||||
|
|
||||||
grammar = """
|
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]*'
|
trim_ws = r'[ \t]*'
|
||||||
eol = "\n" / "\r\n"
|
eol = "\n" / "\r\n"
|
||||||
nonneg_num = r'\d+'
|
nonneg_num = r'\d+'
|
||||||
|
@ -12,7 +13,7 @@ duration = nonneg_num
|
||||||
job_data = ' '* machine ' '+ duration (' '+ machine ' '+ duration)* trim_ws eol
|
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:
|
with open('./inputdata/jobshop2/ta13') as jobdatafile:
|
||||||
jobdata : str = jobdatafile.read()
|
jobdata : str = jobdatafile.read()
|
||||||
|
|
Loading…
Reference in a new issue