diff mercurial/parser.py @ 11412:51ceb1571805

parser: improve infix error checking (spotted by timeless)
author Matt Mackall <mpm@selenic.com>
date Sat, 19 Jun 2010 17:56:52 -0500
parents 9d1cf337a78d
children 05af334bac05
line wrap: on
line diff
--- a/mercurial/parser.py	Sat Jun 19 12:51:57 2010 +0200
+++ b/mercurial/parser.py	Sat Jun 19 17:56:52 2010 -0500
@@ -62,13 +62,13 @@
                 expr = (suffix[0], expr)
             else:
                 # handle infix rules
-                infix = self._elements[token][2]
+                if len(e) < 3 or not e[2]:
+                    raise error.ParseError("not an infix: %s" % token, pos)
+                infix = e[2]
                 if len(infix) == 3 and infix[2] == self.current[0]:
                     self._match(infix[2], pos)
                     expr = (infix[0], expr, (None))
                 else:
-                    if not infix[0]:
-                        raise error.ParseError("not an infix: %s" % token, pos)
                     expr = (infix[0], expr, self._parse(infix[1]))
                     if len(infix) == 3:
                         self._match(infix[2], pos)