Remove empty literals when concatenating regexes
This commit is contained in:
parent
8e052ddd97
commit
46aab39ee6
12
regex.py
12
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:
|
||||
|
|
Loading…
Reference in New Issue