mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Parentheses around chained assignments are not necessary.
We follow the precedence and associativity rules, though.
This commit is contained in:
parent
2e29cc9131
commit
a2e793df02
1 changed files with 11 additions and 3 deletions
|
@ -35,6 +35,7 @@ class outscript(object):
|
|||
'||':1, '&&':1, '|':2, '^':3, '&':4, '==':5, '!=':5,
|
||||
'<':6, '<=':6, '>':6, '>=':6, '<<':7, '>>':7, '+':8, '-':8,# 'NEG':8,
|
||||
'*':9, '/':9, '%':9}#, '!':10, '~':10, '++':10, '--':10, }
|
||||
assignment_ops = ('=', '+=', '-=', '*=', '/=','%=')
|
||||
|
||||
def Value2LSL(self, value):
|
||||
tvalue = type(value)
|
||||
|
@ -220,7 +221,14 @@ class outscript(object):
|
|||
lparen = False
|
||||
rnt = child[1]['nt']
|
||||
rparen = False
|
||||
if nt in self.op_priority:
|
||||
if nt in self.assignment_ops and nt in self.op_priority:
|
||||
# Assignment is right-associative, so it needs to be dealt with
|
||||
# separately.
|
||||
base_pri = self.op_priority[nt]
|
||||
if rnt in self.op_priority:
|
||||
if self.op_priority[rnt] < base_pri: # should never happen
|
||||
rparen = True
|
||||
elif nt in self.op_priority:
|
||||
base_pri = self.op_priority[nt]
|
||||
if lnt in self.op_priority:
|
||||
if self.op_priority[lnt] < base_pri:
|
||||
|
@ -228,8 +236,8 @@ class outscript(object):
|
|||
elif lnt == 'NEG' and base_pri > self.op_priority['-']:
|
||||
lparen = True
|
||||
|
||||
# This situation has ugly cases due to the strange priority of
|
||||
# unary minus. Consider the following two statements:
|
||||
# This situation has ugly cases due to the strange precedence
|
||||
# of unary minus. Consider the following two statements:
|
||||
# (~-a) * a
|
||||
# a * (~-a) * a
|
||||
# In one case, the (~-a) is a left child; in the other, it's
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue