Evaluate an expression of minus and tilde Given an expression matching the regex /^[-~]*x$/, evaluate it in terms of x and output a string matching the regex /^-?x[+-]\d+$/.

For example, the string -~x evaluates to x+1, while the string -~-x evaluates to -x+1, and the string -~-~--x evaluates to x+2.

We start from x and evaluate the string right to left. - negates the term, while ~ converts y to -y-1.

Testcases:

    x  x+0
   ~x -x-1
  -~x  x+1
 ~-~x -x-2
-~-~x  x+2
--~~x  x+0
  ~-x  x-1
 -~-x -x+1


This is code-golf. Shortest answer in bytes wins.

The input/output format is strict. The "x" is mandatory.
Python 2, 42 41 39 bytes



lambda s,x=0:'-x%+d'[len(s)%2:]%eval(s)


Try it online!