[PATCH RFC] templater: provide ring operations on integers

Yuya Nishihara yuya at tcha.org
Sun Oct 9 06:52:46 EDT 2016


On Sat, 8 Oct 2016 18:26:30 +0200, Simon Farnsworth wrote:
> This is RFC because I have no idea what I'm doing in the parser. If
> someone at the sprint has 5 minutes available to educate me, I can
> update this to a better version.
> 
> On 08/10/2016 18:24, Simon Farnsworth wrote:
> > # HG changeset patch
> > # User Simon Farnsworth <simonfar at fb.com>
> > # Date 1475943860 25200
> > #      Sat Oct 08 09:24:20 2016 -0700
> > # Node ID e89699ba5c9f0bf883bfae7c485e50219b90b2f9
> > # Parent  91a3c58ecf938ed675f5364b88f0d663f12b0047
> > templater: provide ring operations on integers

This generally looks good to me.

A few nits follow.

> > --- a/mercurial/templater.py
> > +++ b/mercurial/templater.py
> > @@ -33,6 +33,9 @@
> >      "|": (5, None, None, ("|", 5), None),
> >      "%": (6, None, None, ("%", 6), None),
> >      ")": (0, None, None, None, None),
> > +    "+": (10, None, None, ("+", 10), None),
> > +    "-": (10, None, ("negate", 10), ("-", 10), None),
> > +    "*": (12, None, None, ("*", 12), None),

Perhaps these operators should have lower binding values than template
operations so 'x|y - z' is parsed as (x|y) - z.

  $ hg debugtemplate -r0 -v '{revset(".")|count - 1}\n'

but "negate" will still need higher binding limit.

  $ hg debugtemplate -r0 -v '{-3|stringify}\n'

https://selenic.com/repo/hg/rev/e797fdf91df4

> > -        elif c.isdigit() or c == '-':
> > +        elif c.isdigit():
> >              s = pos

We can remove the next 4 or 5 lines which were necessary to handle '-'.

> >              if c == '-': # simply take negate operator as part of integer
> >                  pos += 1


More information about the Mercurial-devel mailing list