diff --git a/regexp.py b/regexp.py --- a/regexp.py +++ b/regexp.py @@ -52,7 +52,9 @@ class Symbol(Token): return self.value -class Plus(Token): +class Asterisk(Token): + is_skippable = True + def __init__(self, content: Token): self.content = content @@ -69,13 +71,6 @@ class Plus(Token): yield (x, y) def __str__(self): - return str(self.content) + "+" - - -class Asterisk(Plus): - is_skippable = True - - def __str__(self): return str(self.content) + "*" @@ -188,16 +183,9 @@ def parse(pattern, offset=0): raise ParsingError(f'The asterisk operator is missing an argument. Pattern: "{pattern}", position {i}') res.append(Asterisk(token)) i += 1 - elif c == "+": - try: - token = res.pop() - except IndexError as e: - raise ParsingError(f'The plus operator is missing an argument. Pattern: "{pattern}", position {i}') - res.append(Plus(token)) - i += 1 elif c == ")": raise ParsingError(f'An opening parenthesis not found. Pattern: "{pattern}", position: {i}') - elif c == "|": + elif c == "|" or c == "+": is_alternative = True res.append(AlternativeSeparator()) i += 1