mercurial/fileset.py
changeset 35741 73432eee0ac4
parent 35739 9eb5c400f488
child 35950 7b2b82f891bf
equal deleted inserted replaced
35740:06a757b9e334 35741:73432eee0ac4
    22 )
    22 )
    23 
    23 
    24 elements = {
    24 elements = {
    25     # token-type: binding-strength, primary, prefix, infix, suffix
    25     # token-type: binding-strength, primary, prefix, infix, suffix
    26     "(": (20, None, ("group", 1, ")"), ("func", 1, ")"), None),
    26     "(": (20, None, ("group", 1, ")"), ("func", 1, ")"), None),
       
    27     ":": (15, None, None, ("kindpat", 15), None),
    27     "-": (5, None, ("negate", 19), ("minus", 5), None),
    28     "-": (5, None, ("negate", 19), ("minus", 5), None),
    28     "not": (10, None, ("not", 10), None, None),
    29     "not": (10, None, ("not", 10), None, None),
    29     "!": (10, None, ("not", 10), None, None),
    30     "!": (10, None, ("not", 10), None, None),
    30     "and": (5, None, None, ("and", 5), None),
    31     "and": (5, None, None, ("and", 5), None),
    31     "&": (5, None, None, ("and", 5), None),
    32     "&": (5, None, None, ("and", 5), None),
    48     program = pycompat.bytestr(program)
    49     program = pycompat.bytestr(program)
    49     while pos < l:
    50     while pos < l:
    50         c = program[pos]
    51         c = program[pos]
    51         if c.isspace(): # skip inter-token whitespace
    52         if c.isspace(): # skip inter-token whitespace
    52             pass
    53             pass
    53         elif c in "(),-|&+!": # handle simple operators
    54         elif c in "(),-:|&+!": # handle simple operators
    54             yield (c, None, pos)
    55             yield (c, None, pos)
    55         elif (c in '"\'' or c == 'r' and
    56         elif (c in '"\'' or c == 'r' and
    56               program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
    57               program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
    57             if c == 'r':
    58             if c == 'r':
    58                 pos += 1
    59                 pos += 1
   108 def getstring(x, err):
   109 def getstring(x, err):
   109     if x and (x[0] == 'string' or x[0] == 'symbol'):
   110     if x and (x[0] == 'string' or x[0] == 'symbol'):
   110         return x[1]
   111         return x[1]
   111     raise error.ParseError(err)
   112     raise error.ParseError(err)
   112 
   113 
       
   114 def _getkindpat(x, y, allkinds, err):
       
   115     kind = getsymbol(x)
       
   116     pat = getstring(y, err)
       
   117     if kind not in allkinds:
       
   118         raise error.ParseError(_("invalid pattern kind: %s") % kind)
       
   119     return '%s:%s' % (kind, pat)
       
   120 
       
   121 def getpattern(x, allkinds, err):
       
   122     if x and x[0] == 'kindpat':
       
   123         return _getkindpat(x[1], x[2], allkinds, err)
       
   124     return getstring(x, err)
       
   125 
   113 def getset(mctx, x):
   126 def getset(mctx, x):
   114     if not x:
   127     if not x:
   115         raise error.ParseError(_("missing argument"))
   128         raise error.ParseError(_("missing argument"))
   116     return methods[x[0]](mctx, *x[1:])
   129     return methods[x[0]](mctx, *x[1:])
   117 
   130 
   118 def stringset(mctx, x):
   131 def stringset(mctx, x):
   119     m = mctx.matcher([x])
   132     m = mctx.matcher([x])
   120     return [f for f in mctx.subset if m(f)]
   133     return [f for f in mctx.subset if m(f)]
       
   134 
       
   135 def kindpatset(mctx, x, y):
       
   136     return stringset(mctx, _getkindpat(x, y, matchmod.allpatternkinds,
       
   137                                        _("pattern must be a string")))
   121 
   138 
   122 def andset(mctx, x, y):
   139 def andset(mctx, x, y):
   123     return getset(mctx.narrow(getset(mctx, x)), y)
   140     return getset(mctx.narrow(getset(mctx, x)), y)
   124 
   141 
   125 def orset(mctx, x, y):
   142 def orset(mctx, x, y):
   505     # i18n: "subrepo" is a keyword
   522     # i18n: "subrepo" is a keyword
   506     getargs(x, 0, 1, _("subrepo takes at most one argument"))
   523     getargs(x, 0, 1, _("subrepo takes at most one argument"))
   507     ctx = mctx.ctx
   524     ctx = mctx.ctx
   508     sstate = sorted(ctx.substate)
   525     sstate = sorted(ctx.substate)
   509     if x:
   526     if x:
   510         # i18n: "subrepo" is a keyword
   527         pat = getpattern(x, matchmod.allpatternkinds,
   511         pat = getstring(x, _("subrepo requires a pattern or no arguments"))
   528                          # i18n: "subrepo" is a keyword
       
   529                          _("subrepo requires a pattern or no arguments"))
   512         fast = not matchmod.patkind(pat)
   530         fast = not matchmod.patkind(pat)
   513         if fast:
   531         if fast:
   514             def m(s):
   532             def m(s):
   515                 return (s == pat)
   533                 return (s == pat)
   516         else:
   534         else:
   520         return [sub for sub in sstate]
   538         return [sub for sub in sstate]
   521 
   539 
   522 methods = {
   540 methods = {
   523     'string': stringset,
   541     'string': stringset,
   524     'symbol': stringset,
   542     'symbol': stringset,
       
   543     'kindpat': kindpatset,
   525     'and': andset,
   544     'and': andset,
   526     'or': orset,
   545     'or': orset,
   527     'minus': minusset,
   546     'minus': minusset,
   528     'negate': negateset,
   547     'negate': negateset,
   529     'list': listset,
   548     'list': listset,