improve module

This commit is contained in:
Trolli Schmittlauch 2017-06-27 23:49:52 +02:00
parent 901472e8b5
commit c3953449ff

View file

@ -1,6 +1,8 @@
from typing import List, Tuple, Sequence, Optional, Union from typing import List, Tuple, Sequence, Optional, Union
import arpeggio import arpeggio
__all__ = ["jobshop1_parser", "jobshop2_parser"]
grammar = """ grammar = """
# starting point for jobshop1 input file # starting point for jobshop1 input file
job_shop1 = skip_preface job_shop1 = skip_preface
@ -78,7 +80,7 @@ class JobShopVisitor(arpeggio.PTNodeVisitor):
if len(job_numbers) % 2 ==1: if len(job_numbers) % 2 ==1:
raise ParseError("Odd number of numbers in job data") raise ParseError("Odd number of numbers in job data")
# returns list of (duration, machine) tuples # returns list of (duration, machine) tuples
return list(zip(job_numbers[1::2], job_numbers[0::2])) return list(zip(job_numbers[1::2], job_numbers[0::2])) # [::2] returns only every second element of the list
def visit_problem_data(self, node: arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> JobShopProblem: def visit_problem_data(self, node: arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> JobShopProblem:
if self.debug: if self.debug: