From 608af7d2ff9eda9bb0064092431cdf0ec0fcdc5f Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Thu, 22 Jun 2017 23:12:18 +0200 Subject: [PATCH] [untested] first grammar definition with parsimonious - added parsimonious as requirement - first try of creating a grammar for job_shop1 --- requirements.txt | 1 + src/JobShopParser/__init__.py | 0 src/JobShopParser/jobshop1_parser.py | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 src/JobShopParser/__init__.py create mode 100644 src/JobShopParser/jobshop1_parser.py diff --git a/requirements.txt b/requirements.txt index f0aa93a..1a2f7b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ mypy +parsimonious diff --git a/src/JobShopParser/__init__.py b/src/JobShopParser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/JobShopParser/jobshop1_parser.py b/src/JobShopParser/jobshop1_parser.py new file mode 100644 index 0000000..a064077 --- /dev/null +++ b/src/JobShopParser/jobshop1_parser.py @@ -0,0 +1,19 @@ +from parsomonious.grammar import Grammar + +grammar = 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 + """) +