mercurial/parser.py
changeset 11278 7df88cdf47fd
parent 11274 77272d28b53f
child 11289 4215ce511134
--- a/mercurial/parser.py	Tue Jun 01 11:18:57 2010 -0500
+++ b/mercurial/parser.py	Wed Jun 02 14:07:46 2010 -0500
@@ -23,7 +23,10 @@
     def _advance(self):
         'advance the tokenizer'
         t = self.current
-        self.current = self._iter.next()
+        try:
+            self.current = self._iter.next()
+        except StopIteration:
+            pass
         return t
     def _match(self, m):
         'make sure the tokenizer matches an end condition'
@@ -49,17 +52,23 @@
         # gather tokens until we meet a lower binding strength
         while bind < self._elements[self.current[0]][0]:
             token, value = self._advance()
-            # handle infix rules
-            infix = self._elements[token][2]
-            if len(infix) == 3 and infix[2] == self.current[0]:
-                self._match(infix[2])
-                expr = (infix[0], expr, (None))
+            e = self._elements[token]
+            # check for suffix - next token isn't a valid prefix
+            if len(e) == 4 and not self._elements[self.current[0]][1]:
+                suffix = e[3]
+                expr = (suffix[0], expr)
             else:
-                if not infix[0]:
-                    raise SyntaxError("not an infix")
-                expr = (infix[0], expr, self._parse(infix[1]))
-                if len(infix) == 3:
+                # handle infix rules
+                infix = self._elements[token][2]
+                if len(infix) == 3 and infix[2] == self.current[0]:
                     self._match(infix[2])
+                    expr = (infix[0], expr, (None))
+                else:
+                    if not infix[0]:
+                        raise SyntaxError("not an infix")
+                    expr = (infix[0], expr, self._parse(infix[1]))
+                    if len(infix) == 3:
+                        self._match(infix[2])
         return expr
     def parse(self, message):
         'generate a parse tree from a message'