parser: improve infix error checking
authorMatt Mackall <mpm@selenic.com>
Sat, 19 Jun 2010 17:56:52 -0500
changeset 11412 51ceb1571805
parent 11411 5834e79b24f7
child 11413 4c1fe996838c
parser: improve infix error checking (spotted by timeless)
mercurial/parser.py
--- 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)