mercurial/revset.py
changeset 28874 552eabef663b
parent 28873 2ca3b7c563f3
child 28875 2e9f5453ab5a
equal deleted inserted replaced
28873:2ca3b7c563f3 28874:552eabef663b
  2232     examine whether ``$`` is used also for unexpected symbols or not.
  2232     examine whether ``$`` is used also for unexpected symbols or not.
  2233     """
  2233     """
  2234     return tokenize(program, lookup=lookup,
  2234     return tokenize(program, lookup=lookup,
  2235                     syminitletters=_aliassyminitletters)
  2235                     syminitletters=_aliassyminitletters)
  2236 
  2236 
  2237 def _parsealiasdecl(decl):
  2237 def _parsealias(spec):
  2238     """Parse alias declaration ``decl``
  2238     """Parse alias declaration/definition ``spec``
  2239 
  2239 
  2240     >>> _parsealiasdecl('foo($1)')
  2240     >>> _parsealias('foo($1)')
  2241     ('func', ('symbol', 'foo'), ('symbol', '$1'))
  2241     ('func', ('symbol', 'foo'), ('symbol', '$1'))
  2242     >>> _parsealiasdecl('foo bar')
  2242     >>> _parsealias('foo bar')
  2243     Traceback (most recent call last):
  2243     Traceback (most recent call last):
  2244       ...
  2244       ...
  2245     ParseError: ('invalid token', 4)
  2245     ParseError: ('invalid token', 4)
  2246     """
  2246     """
  2247     p = parser.parser(elements)
  2247     p = parser.parser(elements)
  2248     tree, pos = p.parse(_tokenizealias(decl))
  2248     tree, pos = p.parse(_tokenizealias(spec))
  2249     if pos != len(decl):
  2249     if pos != len(spec):
  2250         raise error.ParseError(_('invalid token'), pos)
       
  2251     return parser.simplifyinfixops(tree, ('list',))
       
  2252 
       
  2253 def _parsealiasdefn(defn):
       
  2254     """Parse alias definition ``defn``"""
       
  2255     p = parser.parser(elements)
       
  2256     tree, pos = p.parse(_tokenizealias(defn))
       
  2257     if pos != len(defn):
       
  2258         raise error.ParseError(_('invalid token'), pos)
  2250         raise error.ParseError(_('invalid token'), pos)
  2259     return parser.simplifyinfixops(tree, ('list', 'or'))
  2251     return parser.simplifyinfixops(tree, ('list', 'or'))
  2260 
  2252 
  2261 class _aliasrules(parser.basealiasrules):
  2253 class _aliasrules(parser.basealiasrules):
  2262     """Parsing and expansion rule set of revset aliases"""
  2254     """Parsing and expansion rule set of revset aliases"""
  2263     _section = _('revset alias')
  2255     _section = _('revset alias')
  2264     _parsedecl = staticmethod(_parsealiasdecl)
  2256     _parsedecl = staticmethod(_parsealias)
  2265     _parsedefn = staticmethod(_parsealiasdefn)
  2257     _parsedefn = staticmethod(_parsealias)
  2266     _getlist = staticmethod(getlist)
  2258     _getlist = staticmethod(getlist)
  2267 
  2259 
  2268 class revsetalias(object):
  2260 class revsetalias(object):
  2269     # whether own `error` information is already shown or not.
  2261     # whether own `error` information is already shown or not.
  2270     # this avoids showing same warning multiple times at each `findaliases`.
  2262     # this avoids showing same warning multiple times at each `findaliases`.