Logic for [] was too simple, remove it for time being
This commit is contained in:
parent
fdb5797ee0
commit
2b74819b15
11
regex.py
11
regex.py
|
@ -47,13 +47,9 @@ class Alternation:
|
||||||
return 'Alternation(%s)' % ', '.join(map(repr, self.elements))
|
return 'Alternation(%s)' % ', '.join(map(repr, self.elements))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if all(type(i) == Literal and i.single_char for i in self.elements):
|
# Nothing binds looser than alternation, so just pass
|
||||||
# Special case: [abc]
|
# everything through as-is
|
||||||
return '[%s]' % ''.join(map(str, self.elements))
|
return '|'.join(map(str, self.elements))
|
||||||
else:
|
|
||||||
# Nothing binds looser than alternation, so just
|
|
||||||
# pass everything through as-is
|
|
||||||
return '|'.join(map(str, self.elements))
|
|
||||||
|
|
||||||
class Star:
|
class Star:
|
||||||
def __init__(self, element):
|
def __init__(self, element):
|
||||||
|
@ -75,6 +71,7 @@ def lit(text):
|
||||||
return Literal(text)
|
return Literal(text)
|
||||||
|
|
||||||
def concat(*elements):
|
def concat(*elements):
|
||||||
|
# TODO: drop literals that are just ''
|
||||||
flattened = []
|
flattened = []
|
||||||
for element in elements:
|
for element in elements:
|
||||||
if type(element) == Concatenation:
|
if type(element) == Concatenation:
|
||||||
|
|
Loading…
Reference in New Issue