Add 'assertExpected' to Parser.oneOf() method
This commit is contained in:
@@ -62,7 +62,7 @@ class Parser:
|
||||
|
||||
# oneOf -> a | b | c | ...
|
||||
@staticmethod
|
||||
def oneOf(*parsers, exception=None, name="or"):
|
||||
def oneOf(*parsers, assertExpected=None, exception=None, name="or"):
|
||||
def combinedParser(input):
|
||||
snap = input.snapshot()
|
||||
for parser in parsers:
|
||||
@@ -70,6 +70,10 @@ class Parser:
|
||||
if value.result:
|
||||
return value
|
||||
|
||||
if assertExpected is not None:
|
||||
found = f", found '{input.current().rawValue}'" if input.hasCurrent() else ""
|
||||
raise SyntaxException(f"Expected {assertExpected}{found}", input.currentPos())
|
||||
|
||||
if exception is not None:
|
||||
if callable(exception):
|
||||
raise exception(input)
|
||||
|
||||
Reference in New Issue
Block a user