From 2b74819b15ed598c7146714316cc06b7e96cca40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Fri, 31 May 2019 14:06:39 +0300 Subject: [PATCH] Logic for [] was too simple, remove it for time being --- regex.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/regex.py b/regex.py index 0de89ec..3baf5f5 100644 --- a/regex.py +++ b/regex.py @@ -47,13 +47,9 @@ class Alternation: return 'Alternation(%s)' % ', '.join(map(repr, self.elements)) def __str__(self): - if all(type(i) == Literal and i.single_char for i in self.elements): - # Special case: [abc] - return '[%s]' % ''.join(map(str, self.elements)) - else: - # Nothing binds looser than alternation, so just - # pass everything through as-is - return '|'.join(map(str, self.elements)) + # Nothing binds looser than alternation, so just pass + # everything through as-is + return '|'.join(map(str, self.elements)) class Star: def __init__(self, element): @@ -75,6 +71,7 @@ def lit(text): return Literal(text) def concat(*elements): + # TODO: drop literals that are just '' flattened = [] for element in elements: if type(element) == Concatenation: