comparison mercurial/parser.py @ 25816:43a8a87fc175

parser: resolve ambiguity where both prefix and primary actions are defined If both actions are defined, a primary-expression action is accepted only if the next token never starts new term. For example, parsed as primary expression: ":" # next token 'end' has no action "(:)" # next token ')' has no action ":+y" # next token '+' is infix operator parsed as prefix operator: ":y" # next token 'y' is primary expression ":-y" # next token '-' is prefix operator This is mostly the same resolution as the infix/suffix rules.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 05 Jul 2015 12:09:27 +0900
parents e71e5629e006
children 42ac9d1d1572
comparison
equal deleted inserted replaced
25815:e71e5629e006 25816:43a8a87fc175
47 if m: 47 if m:
48 self._match(m) 48 self._match(m)
49 return expr 49 return expr
50 def _parse(self, bind=0): 50 def _parse(self, bind=0):
51 token, value, pos = self._advance() 51 token, value, pos = self._advance()
52 # handle prefix rules on current token 52 # handle prefix rules on current token, take as primary if unambiguous
53 primary, prefix = self._elements[token][1:3] 53 primary, prefix = self._elements[token][1:3]
54 if primary: 54 if primary and not (prefix and self._hasnewterm()):
55 expr = (primary, value) 55 expr = (primary, value)
56 elif prefix: 56 elif prefix:
57 expr = (prefix[0], self._parseoperand(*prefix[1:])) 57 expr = (prefix[0], self._parseoperand(*prefix[1:]))
58 else: 58 else:
59 raise error.ParseError(_("not a prefix: %s") % token, pos) 59 raise error.ParseError(_("not a prefix: %s") % token, pos)