Skip to content

Commit 0c8f716

Browse files
committed
Adjust the precedence
This adjusts the precedence rules to be more closely aligned to Python
1 parent 1ee18f3 commit 0c8f716

File tree

3 files changed

+292
-290
lines changed

3 files changed

+292
-290
lines changed

lib/rule_engine/parser/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,22 @@ class Parser(ParserBase):
143143
# reverse the order to lowest to highest for ply
144144
reversed((
145145
('nonassoc', 'LPAREN', 'RPAREN'),
146+
('nonassoc', 'LBRACKET', 'RBRACKET'),
146147
('left', 'ATTR', 'ATTR_SAFE'),
147-
('right', 'UMINUS'),
148148
('left', 'POW'),
149+
('right', 'UMINUS'),
149150
('left', 'MUL', 'TDIV', 'FDIV', 'MOD'),
150-
('left', 'BWLSH', 'BWRSH'),
151151
('left', 'ADD', 'SUB'),
152-
('nonassoc', 'EQ', 'NE', 'EQ_FZM', 'EQ_FZS', 'NE_FZM', 'NE_FZS', 'GE', 'GT', 'LE', 'LT', 'IN'), # Nonassociative operators
153-
('right', 'QMARK', 'COLON'),
152+
('left', 'BWLSH', 'BWRSH'),
154153
('left', 'BWAND'),
155154
('left', 'BWXOR'),
156155
('left', 'BWOR'),
156+
('nonassoc', 'EQ_FZM', 'EQ_FZS', 'NE_FZM', 'NE_FZS', 'GE', 'GT', 'LE', 'LT', 'IN'), # Nonassociative operators
157+
('nonassoc', 'EQ', 'NE'),
157158
('right', 'NOT'),
158159
('left', 'AND'),
159160
('left', 'OR'),
161+
('right', 'QMARK', 'COLON'),
160162
)
161163
))
162164

0 commit comments

Comments
 (0)