[PATCH v2] templater: provide arithmetic operations on integers

Simon Farnsworth simonfar at fb.com
Sun Oct 9 11:04:08 EDT 2016


On 09/10/2016 16:51, Yuya Nishihara wrote:
> On Sun, 9 Oct 2016 05:53:25 -0700, Simon Farnsworth wrote:
>> # HG changeset patch
>> # User Simon Farnsworth <simonfar at fb.com>
>> # Date 1476017464 25200
>> #      Sun Oct 09 05:51:04 2016 -0700
>> # Node ID 2e2c959de0fe2c17bf6c5f47c01035a36f13c593
>> # Parent  dbcef8918bbdd8a64d9f79a37bcfa284a26f3a39
>> templater: provide arithmetic operations on integers
>
> Nice. Queued slight modified version, thanks.
>
> We'll need to catch ZeroDivisionError as a follow-up.

Follow-up incoming to turn ZeroDivisionError into an abort (and to reuse 
runarithmetic() in mod()).

<snip>

>> +But negate binds closer still:
>> +
>> +  $ hg debugtemplate -r0 -v '{1-3|stringify}\n'
>> +  (template
>> +    (-
>> +      ('integer', '1')
>> +      (|
>> +        ('integer', '3')
>> +        ('symbol', 'stringify')))
>> +    ('string', '\n'))
>> +  hg: parse error: arithmetic only defined on integers
>> +  [255]
>
> For the record, this fails because '3' is taken as a keyword (for backward
> compatibility), and evaluated to ''.
>
Indeed - the parse tree is the important bit here, not the failure, as 
it shows that we've parsed '1-3' as a subtraction with the right 
precedence, not as '1' then '-3'.
-- 
Simon Farnsworth


More information about the Mercurial-devel mailing list