mercurial/templater.py
changeset 31885 d18b624c1c06
parent 31884 0926ca37a990
child 31886 bdda942f4b9c
equal deleted inserted replaced
31884:0926ca37a990 31885:d18b624c1c06
    37     "|": (15, None, None, ("|", 15), None),
    37     "|": (15, None, None, ("|", 15), None),
    38     "*": (5, None, None, ("*", 5), None),
    38     "*": (5, None, None, ("*", 5), None),
    39     "/": (5, None, None, ("/", 5), None),
    39     "/": (5, None, None, ("/", 5), None),
    40     "+": (4, None, None, ("+", 4), None),
    40     "+": (4, None, None, ("+", 4), None),
    41     "-": (4, None, ("negate", 19), ("-", 4), None),
    41     "-": (4, None, ("negate", 19), ("-", 4), None),
       
    42     "=": (3, None, None, ("keyvalue", 3), None),
    42     ",": (2, None, None, ("list", 2), None),
    43     ",": (2, None, None, ("list", 2), None),
    43     ")": (0, None, None, None, None),
    44     ")": (0, None, None, None, None),
    44     "integer": (0, "integer", None, None, None),
    45     "integer": (0, "integer", None, None, None),
    45     "symbol": (0, "symbol", None, None, None),
    46     "symbol": (0, "symbol", None, None, None),
    46     "string": (0, "string", None, None, None),
    47     "string": (0, "string", None, None, None),
    54     pos = start
    55     pos = start
    55     while pos < end:
    56     while pos < end:
    56         c = program[pos]
    57         c = program[pos]
    57         if c.isspace(): # skip inter-token whitespace
    58         if c.isspace(): # skip inter-token whitespace
    58             pass
    59             pass
    59         elif c in "(,)%|+-*/": # handle simple operators
    60         elif c in "(=,)%|+-*/": # handle simple operators
    60             yield (c, None, pos)
    61             yield (c, None, pos)
    61         elif c in '"\'': # handle quoted templates
    62         elif c in '"\'': # handle quoted templates
    62             s = pos + 1
    63             s = pos + 1
    63             data, pos = _parsetemplate(program, s, end, c)
    64             data, pos = _parsetemplate(program, s, end, c)
    64             yield ('template', data, s)
    65             yield ('template', data, s)
   460             raise error.ParseError(_("filter %s expects one argument") % n)
   461             raise error.ParseError(_("filter %s expects one argument") % n)
   461         f = context._filters[n]
   462         f = context._filters[n]
   462         return (runfilter, (args[0], f))
   463         return (runfilter, (args[0], f))
   463     raise error.ParseError(_("unknown function '%s'") % n)
   464     raise error.ParseError(_("unknown function '%s'") % n)
   464 
   465 
       
   466 def buildkeyvaluepair(exp, content):
       
   467     raise error.ParseError(_("can't use a key-value pair in this context"))
       
   468 
   465 # dict of template built-in functions
   469 # dict of template built-in functions
   466 funcs = {}
   470 funcs = {}
   467 
   471 
   468 templatefunc = registrar.templatefunc(funcs)
   472 templatefunc = registrar.templatefunc(funcs)
   469 
   473 
   982     "group": lambda e, c: compileexp(e[1], c, exprmethods),
   986     "group": lambda e, c: compileexp(e[1], c, exprmethods),
   983 #    ".": buildmember,
   987 #    ".": buildmember,
   984     "|": buildfilter,
   988     "|": buildfilter,
   985     "%": buildmap,
   989     "%": buildmap,
   986     "func": buildfunc,
   990     "func": buildfunc,
       
   991     "keyvalue": buildkeyvaluepair,
   987     "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
   992     "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
   988     "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
   993     "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
   989     "negate": buildnegate,
   994     "negate": buildnegate,
   990     "*": lambda e, c: buildarithmetic(e, c, lambda a, b: a * b),
   995     "*": lambda e, c: buildarithmetic(e, c, lambda a, b: a * b),
   991     "/": lambda e, c: buildarithmetic(e, c, lambda a, b: a // b),
   996     "/": lambda e, c: buildarithmetic(e, c, lambda a, b: a // b),