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: