Patchwork [5,of,5] parser: extract function that tests if next token may start new term

login
register
mail settings
Submitter Yuya Nishihara
Date July 14, 2015, 2:44 p.m.
Message ID <d798dd7bb3c6fdcd994d.1436885069@mimosa>
Download mbox | patch
Permalink /patch/9975/
State Accepted
Headers show

Comments

Yuya Nishihara - July 14, 2015, 2:44 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1436064854 -32400
#      Sun Jul 05 11:54:14 2015 +0900
# Node ID d798dd7bb3c6fdcd994de0db94dd50c843fffc41
# Parent  c98978f8aaeb6db1b770a54921147e7d3836a050
parser: extract function that tests if next token may start new term

Future patches will separate primary expression and prefix operator actions.
This function will be used to resolve ambiguity of them.

This is a step to remove the old-style revexpr parser. We need both ":" and
":y" operators for backward compatibility.
Matt Mackall - July 15, 2015, 9:34 p.m.
On Tue, 2015-07-14 at 23:44 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1436064854 -32400
> #      Sun Jul 05 11:54:14 2015 +0900
> # Node ID d798dd7bb3c6fdcd994de0db94dd50c843fffc41
> # Parent  c98978f8aaeb6db1b770a54921147e7d3836a050
> parser: extract function that tests if next token may start new term

These are queued for default, thanks.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -29,6 +29,9 @@  class parser(object):
         t = self.current
         self.current = next(self._iter, None)
         return t
+    def _hasnewterm(self):
+        'True if next token may start new term'
+        return bool(self._elements[self.current[0]][1])
     def _match(self, m):
         'make sure the tokenizer matches an end condition'
         if self.current[0] != m:
@@ -59,7 +62,7 @@  class parser(object):
             token, value, pos = self._advance()
             infix, suffix = self._elements[token][2:]
             # check for suffix - next token isn't a valid prefix
-            if suffix and not self._elements[self.current[0]][1]:
+            if suffix and not self._hasnewterm():
                 expr = (suffix[0], expr)
             else:
                 # handle infix rules