@@ -57,6 +57,12 @@ class Parser(object):
5757 'gte' : 5 ,
5858 'lte' : 5 ,
5959 'ne' : 5 ,
60+ 'minus' : 6 ,
61+ 'plus' : 6 ,
62+ 'div' : 7 ,
63+ 'divide' : 7 ,
64+ 'modulo' : 7 ,
65+ 'multiply' : 7 ,
6066 'flatten' : 9 ,
6167 # Everything above stops a projection.
6268 'star' : 20 ,
@@ -170,6 +176,12 @@ def _token_nud_lparen(self, token):
170176 self ._match ('rparen' )
171177 return expression
172178
179+ def _token_nud_minus (self , token ):
180+ return self ._parse_arithmetic_unary (token )
181+
182+ def _token_nud_plus (self , token ):
183+ return self ._parse_arithmetic_unary (token )
184+
173185 def _token_nud_flatten (self , token ):
174186 left = ast .flatten (ast .identity ())
175187 right = self ._parse_projection_rhs (
@@ -318,6 +330,27 @@ def _token_led_lt(self, left):
318330 def _token_led_lte (self , left ):
319331 return self ._parse_comparator (left , 'lte' )
320332
333+ def _token_led_div (self , left ):
334+ return self ._parse_arithmetic (left , 'div' )
335+
336+ def _token_led_divide (self , left ):
337+ return self ._parse_arithmetic (left , 'divide' )
338+
339+ def _token_led_minus (self , left ):
340+ return self ._parse_arithmetic (left , 'minus' )
341+
342+ def _token_led_modulo (self , left ):
343+ return self ._parse_arithmetic (left , 'modulo' )
344+
345+ def _token_led_multiply (self , left ):
346+ return self ._parse_arithmetic (left , 'multiply' )
347+
348+ def _token_led_plus (self , left ):
349+ return self ._parse_arithmetic (left , 'plus' )
350+
351+ def _token_led_star (self , left ):
352+ return self ._parse_arithmetic (left , 'multiply' )
353+
321354 def _token_led_flatten (self , left ):
322355 left = ast .flatten (left )
323356 right = self ._parse_projection_rhs (
@@ -356,6 +389,14 @@ def _parse_comparator(self, left, comparator):
356389 right = self ._expression (self .BINDING_POWER [comparator ])
357390 return ast .comparator (comparator , left , right )
358391
392+ def _parse_arithmetic_unary (self , token ):
393+ expression = self ._expression (self .BINDING_POWER [token ['type' ]])
394+ return ast .arithmetic_unary (token ['type' ], expression )
395+
396+ def _parse_arithmetic (self , left , operator ):
397+ right = self ._expression (self .BINDING_POWER [operator ])
398+ return ast .arithmetic (operator , left , right )
399+
359400 def _parse_multi_select_list (self ):
360401 expressions = []
361402 while True :
0 commit comments