From a6fdf05ee91902806dcfa51ad9cec6b6e843947b Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 15 May 2021 15:13:34 +0200 Subject: [PATCH] Allow variable whitespace in arrow rules --- CONFIG.md | 6 +++--- PFERD/transformer.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CONFIG.md b/CONFIG.md index cccc751..df3e8f2 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -285,7 +285,7 @@ For this task, the name arrows can be used. They are variants of the normal arrows that only look at the file name instead of the entire path. ``` -\..* -name-re-> ! -__pycache__ -name-> ! -.*\.md -name-re-> ! +\..* -name-re-> ! +__pycache__ -name-> ! +.*\.md -name-re-> ! ``` diff --git a/PFERD/transformer.py b/PFERD/transformer.py index 1b80433..135baf2 100644 --- a/PFERD/transformer.py +++ b/PFERD/transformer.py @@ -255,6 +255,12 @@ def parse_arrow(line: Line) -> str: return "".join(name) +def parse_whitespace(line: Line) -> None: + line.expect(" ") + while line.get() == " ": + line.advance() + + def parse_rule(line: Line) -> Rule: # Parse left side leftindex = line.index @@ -264,13 +270,13 @@ def parse_rule(line: Line) -> Rule: raise RuleParseException(line, "Left side can't be '!'") # Parse arrow - line.expect(" ") + parse_whitespace(line) arrowindex = line.index arrowname = parse_arrow(line) # Parse right side if line.get(): - line.expect(" ") + parse_whitespace(line) right = parse_string(line) else: right = False