CensoredUsername / unrpyc

A ren'py script decompiler
Other
864 stars 157 forks source link

Operator precedence in python code is ignored #11

Closed ghost closed 10 years ago

ghost commented 10 years ago

I noticed this because I had a screen which had a text element that was probably "%.2f" % (float1 - (float2 - float3)) originally but was decompiled to "%.2f" % float1 - float2 - float3 This is of course wrong and leads to an exception because Python interprets this as ((("%.2f" % float1) - float2) - float3) and string minus float is not defined.

The problem seems to be in modules.codegen.SourceGenerator.visit_BinOp, which just prints "left_operator operation right_operator", which only works out if no brackets were used in the original source.

Adding self.write('(') at the beginning and self.write(')') at the end of the method seems to produce code that's more correct but less readable because it also contains a lot of pointless brackets. No idea how a good solution would look like, I just started looking into this code 2 hours ago.

CensoredUsername commented 10 years ago

In case this didn't fix it, please leave a message.