summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2024-03-19 12:38:47 -0700
committerMatthew Sotoudeh <matthew@masot.net>2024-03-19 12:38:47 -0700
commit252ed6aa49514427dcc579a318ddc19fe0680401 (patch)
tree6edc83393c1c393a1b74557d50e4401b68f6d338
parentc18d081357f47d12f59686b19f52ec904484e6b2 (diff)
support +
-rw-r--r--parsers.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/parsers.py b/parsers.py
index 8427137..c851647 100644
--- a/parsers.py
+++ b/parsers.py
@@ -103,6 +103,13 @@ def _regex_to_ast(tokens):
else:
return ('CONCAT', _regex_to_ast(tokens[:-2]),
('KLEENE', _regex_to_ast(tokens[-2:-1])))
+ if tokens[-1] == '+':
+ arg_ast = _regex_to_ast(tokens[:-1])
+ if len(tokens) == 2:
+ return ('CONCAT', arg_ast, ('KLEENE', arg_ast))
+ else:
+ return ('CONCAT', _regex_to_ast(tokens[:-2]),
+ ('CONCAT', arg_ast, ('KLEENE', _regex_to_ast(tokens[-2:-1]))))
return ('CONCAT', _regex_to_ast(tokens[:-1]), _regex_to_ast(tokens[-1:]))
def match_parens(tokens):
@@ -124,7 +131,7 @@ def lex_regex(string):
while string:
if string[0].isspace():
string = string[1:]
- elif string[0] in ("(", ")", "|", "*") + ALPHABET:
+ elif string[0] in ("(", ")", "|", "*", "+") + ALPHABET:
tokens.append(string[0])
string = string[1:]
elif string[0] == "E":
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback