Mercurial > public > mercurial-scm > hg
comparison mercurial/parser.py @ 25804:f0a77cb6316a
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 05 Jul 2015 11:54:14 +0900 |
parents | b3004d273874 |
children | e71e5629e006 |
comparison
equal
deleted
inserted
replaced
25803:b3004d273874 | 25804:f0a77cb6316a |
---|---|
27 def _advance(self): | 27 def _advance(self): |
28 'advance the tokenizer' | 28 'advance the tokenizer' |
29 t = self.current | 29 t = self.current |
30 self.current = next(self._iter, None) | 30 self.current = next(self._iter, None) |
31 return t | 31 return t |
32 def _hasnewterm(self): | |
33 'True if next token may start new term' | |
34 return bool(self._elements[self.current[0]][1]) | |
32 def _match(self, m): | 35 def _match(self, m): |
33 'make sure the tokenizer matches an end condition' | 36 'make sure the tokenizer matches an end condition' |
34 if self.current[0] != m: | 37 if self.current[0] != m: |
35 raise error.ParseError(_("unexpected token: %s") % self.current[0], | 38 raise error.ParseError(_("unexpected token: %s") % self.current[0], |
36 self.current[2]) | 39 self.current[2]) |
57 # gather tokens until we meet a lower binding strength | 60 # gather tokens until we meet a lower binding strength |
58 while bind < self._elements[self.current[0]][0]: | 61 while bind < self._elements[self.current[0]][0]: |
59 token, value, pos = self._advance() | 62 token, value, pos = self._advance() |
60 infix, suffix = self._elements[token][2:] | 63 infix, suffix = self._elements[token][2:] |
61 # check for suffix - next token isn't a valid prefix | 64 # check for suffix - next token isn't a valid prefix |
62 if suffix and not self._elements[self.current[0]][1]: | 65 if suffix and not self._hasnewterm(): |
63 expr = (suffix[0], expr) | 66 expr = (suffix[0], expr) |
64 else: | 67 else: |
65 # handle infix rules | 68 # handle infix rules |
66 if not infix: | 69 if not infix: |
67 raise error.ParseError(_("not an infix: %s") % token, pos) | 70 raise error.ParseError(_("not an infix: %s") % token, pos) |