Skip to content
Snippets Groups Projects
Commit 42ac9d1d authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

parser: reorder infix/suffix handling to be similar to prefix/primary flow

It can be exactly the same flow as the prefix/primary handling. A suffix
action is accepted only if the next token never starts new term.
parent 43a8a87f
No related branches found
No related tags found
No related merge requests found
......@@ -60,4 +60,5 @@
# gather tokens until we meet a lower binding strength
while bind < self._elements[self.current[0]][0]:
token, value, pos = self._advance()
# handle infix rules, take as suffix if unambiguous
infix, suffix = self._elements[token][3:]
......@@ -63,4 +64,3 @@
infix, suffix = self._elements[token][3:]
# check for suffix - next token isn't a valid prefix
if suffix and not self._hasnewterm():
expr = (suffix[0], expr)
......@@ -65,3 +65,5 @@
if suffix and not self._hasnewterm():
expr = (suffix[0], expr)
elif infix:
expr = (infix[0], expr, self._parseoperand(*infix[1:]))
else:
......@@ -67,8 +69,5 @@
else:
# handle infix rules
if not infix:
raise error.ParseError(_("not an infix: %s") % token, pos)
expr = (infix[0], expr, self._parseoperand(*infix[1:]))
raise error.ParseError(_("not an infix: %s") % token, pos)
return expr
def parse(self, tokeniter):
'generate a parse tree from tokens'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment