More ways of writing

Sometimes prettier
This commit is contained in:
John Doty 2024-09-01 06:52:13 -07:00
parent 3012df4ac6
commit 0354fbf4a4
2 changed files with 26 additions and 15 deletions

View file

@ -1715,6 +1715,17 @@ class NothingRule(Rule):
Nothing = NothingRule()
def alt(*args: Rule) -> Rule:
"""A rule that matches one of a series of alternatives.
(A helper function that combines its arguments into nested alternatives.)
"""
result = args[0]
for rule in args[1:]:
result = AlternativeRule(result, rule)
return result
def seq(*args: Rule) -> Rule:
"""A rule that matches a sequence of rules.