Commit c1a33d2c by eckhart

- LaTeX tests repaired

parent 28768306
Showing with 5 additions and 7 deletions
......@@ -1471,7 +1471,7 @@ class Series(NaryOperator):
class Alternative(NaryOperator):
"""
Matches if at least one of several alternatives matches. Returns
Matches if one of several alternatives matches. Returns
the first match.
This parser represents the EBNF-operator "|" with the qualification
......@@ -1491,13 +1491,12 @@ class Alternative(NaryOperator):
EBNF-Notation: `... | ...`
EBNF-Example: `sentence = /\d+\.\d+/ | /\d+/`
"""
def __init__(self, *parsers: Parser, name: str = '') -> None:
def __init__(self, *parsers: Parser, name: str='') -> None:
super(Alternative, self).__init__(*parsers, name=name)
assert len(self.parsers) >= 1
# only the last alternative may be optional. Could this be checked at compile time?
assert all(not isinstance(p, Option) for p in self.parsers[:-1]), \
"Parser-specification Error (EBNF): only the last alternative may be optional!"
self.been_here = dict() # type: Dict[int, int]
def __call__(self, text: StringView) -> Tuple[Node, StringView]:
for parser in self.parsers:
......@@ -1511,7 +1510,6 @@ class Alternative(NaryOperator):
def reset(self):
super(Alternative, self).reset()
self.been_here = {}
return self
# The following operator definitions add syntactical sugar, so one can write:
......@@ -1535,8 +1533,6 @@ class Alternative(NaryOperator):
return self
########################################################################
#
# Flow control operators
......
......@@ -13,8 +13,9 @@ term = { ["§"] factor }+ # "§" means all followin
factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be sure it's not a definition
| [flowmarker] literal
| [flowmarker] regexp
| [flowmarker] group
| [flowmarker] oneormore
| [flowmarker] group
# | [flowmarker] set
| repetition
| option
......@@ -23,6 +24,7 @@ flowmarker = "!" | "&" # '!' negative lookahead, '&' p
retrieveop = "::" | ":" # '::' pop, ':' retrieve
group = "(" §expression ")"
# set = "<" §expression ">"
oneormore = "{" expression "}+"
repetition = "{" §expression "}"
option = "[" §expression "]"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment