Patchwork [3,of,6] parser: reorder infix/suffix handling to be similar to prefix/primary flow

login
register
mail settings
Submitter Yuya Nishihara
Date July 17, 2015, 12:34 p.m.
Message ID <b1c727ea2cccd6c417f4.1437136444@mimosa>
Download mbox | patch
Permalink /patch/10025/
State Accepted
Headers show

Comments

Yuya Nishihara - July 17, 2015, 12:34 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1436187355 -32400
#      Mon Jul 06 21:55:55 2015 +0900
# Node ID b1c727ea2cccd6c417f4315f60f91e08a7227ec8
# Parent  2fc4729950f03b90585d237be6422cd63e926ca9
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.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -60,15 +60,14 @@  class parser(object):
         # 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:]
-            # check for suffix - next token isn't a valid prefix
             if suffix and not self._hasnewterm():
                 expr = (suffix[0], expr)
+            elif infix:
+                expr = (infix[0], expr, self._parseoperand(*infix[1:]))
             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'