diff --git a/regex.py b/regex.py index 3baf5f5..f0d4156 100644 --- a/regex.py +++ b/regex.py @@ -81,7 +81,11 @@ def concat(*elements): combined = [] for element in flattened: - if len(combined) > 0 and type(combined[-1]) == Literal and type(element) == Literal: + if type(element) == Literal and element.text == '': + # Drop empty literals + continue + + elif len(combined) > 0 and type(combined[-1]) == Literal and type(element) == Literal: # Combine two literals next to each other # into one literal previous = combined.pop() @@ -90,7 +94,11 @@ def concat(*elements): else: combined.append(element) - if len(combined) == 1: + if len(combined) == 0: + # Empty regex, represent with empty literal + return lit('') + + elif len(combined) == 1: element, = combined return element else: