Commit c1a33d2c authored by eckhart's avatar eckhart
Browse files

- LaTeX tests repaired

parent 28768306
...@@ -1471,7 +1471,7 @@ class Series(NaryOperator): ...@@ -1471,7 +1471,7 @@ class Series(NaryOperator):
class Alternative(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. the first match.
This parser represents the EBNF-operator "|" with the qualification This parser represents the EBNF-operator "|" with the qualification
...@@ -1491,13 +1491,12 @@ class Alternative(NaryOperator): ...@@ -1491,13 +1491,12 @@ class Alternative(NaryOperator):
EBNF-Notation: `... | ...` EBNF-Notation: `... | ...`
EBNF-Example: `sentence = /\d+\.\d+/ | /\d+/` 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) super(Alternative, self).__init__(*parsers, name=name)
assert len(self.parsers) >= 1 assert len(self.parsers) >= 1
# only the last alternative may be optional. Could this be checked at compile time? # 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]), \ assert all(not isinstance(p, Option) for p in self.parsers[:-1]), \
"Parser-specification Error (EBNF): only the last alternative may be optional!" "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]: def __call__(self, text: StringView) -> Tuple[Node, StringView]:
for parser in self.parsers: for parser in self.parsers:
...@@ -1511,7 +1510,6 @@ class Alternative(NaryOperator): ...@@ -1511,7 +1510,6 @@ class Alternative(NaryOperator):
def reset(self): def reset(self):
super(Alternative, self).reset() super(Alternative, self).reset()
self.been_here = {}
return self return self
# The following operator definitions add syntactical sugar, so one can write: # The following operator definitions add syntactical sugar, so one can write:
...@@ -1535,8 +1533,6 @@ class Alternative(NaryOperator): ...@@ -1535,8 +1533,6 @@ class Alternative(NaryOperator):
return self return self
######################################################################## ########################################################################
# #
# Flow control operators # Flow control operators
......
...@@ -13,8 +13,9 @@ term = { ["§"] factor }+ # "§" means all followin ...@@ -13,8 +13,9 @@ term = { ["§"] factor }+ # "§" means all followin
factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be sure it's not a definition factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be sure it's not a definition
| [flowmarker] literal | [flowmarker] literal
| [flowmarker] regexp | [flowmarker] regexp
| [flowmarker] group
| [flowmarker] oneormore | [flowmarker] oneormore
| [flowmarker] group
# | [flowmarker] set
| repetition | repetition
| option | option
...@@ -23,6 +24,7 @@ flowmarker = "!" | "&" # '!' negative lookahead, '&' p ...@@ -23,6 +24,7 @@ flowmarker = "!" | "&" # '!' negative lookahead, '&' p
retrieveop = "::" | ":" # '::' pop, ':' retrieve retrieveop = "::" | ":" # '::' pop, ':' retrieve
group = "(" §expression ")" group = "(" §expression ")"
# set = "<" §expression ">"
oneormore = "{" expression "}+" oneormore = "{" expression "}+"
repetition = "{" §expression "}" repetition = "{" §expression "}"
option = "[" §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 to comment