diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2024-03-19 12:38:47 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2024-03-19 12:38:47 -0700 |
commit | 252ed6aa49514427dcc579a318ddc19fe0680401 (patch) | |
tree | 6edc83393c1c393a1b74557d50e4401b68f6d338 | |
parent | c18d081357f47d12f59686b19f52ec904484e6b2 (diff) |
support +
-rw-r--r-- | parsers.py | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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": |