@@ -413,9 +413,10 @@ def escape_literal(string):
413
413
414
414
415
415
class ExprParser (object ):
416
- def __init__ (self , string , allow_relational = False ):
416
+ def __init__ (self , string , allow_relational = True ):
417
417
self .string = string
418
418
self .tokens = []
419
+ self .path_name_queue = []
419
420
self .pos = 0
420
421
self ._allow_relational_columns = allow_relational
421
422
self .placeholder_name_to_position = {}
@@ -624,8 +625,9 @@ def assert_cur_token(self, token_type):
624
625
"tokens left" .format (token_type , self .pos ))
625
626
if self .tokens [self .pos ].token_type != token_type :
626
627
raise ValueError ("Expected token type {0} at pos {1} but found "
627
- "type {2}" .format (token_type , self .pos ,
628
- self .tokens [self .pos ]))
628
+ "type {2}, on tokens {3}"
629
+ "" .format (token_type , self .pos ,
630
+ self .tokens [self .pos ], self .tokens ))
629
631
630
632
def cur_token_type_is (self , token_type ):
631
633
return self .pos_token_type_is (self .pos , token_type )
@@ -656,13 +658,24 @@ def paren_expr_list(self):
656
658
list and return a list of Expr objects.
657
659
"""
658
660
exprs = []
661
+ path_name_added = False
659
662
self .consume_token (TokenType .LPAREN )
660
663
if not self .cur_token_type_is (TokenType .RPAREN ):
661
- exprs .append (self ._expr ().get_message ())
664
+ msg_expr = self ._expr ().get_message ()
665
+ if hasattr (msg_expr , "identifier" ) and msg_expr .identifier .name :
666
+ self .path_name_queue .insert (0 , msg_expr .identifier .name )
667
+ path_name_added = True
668
+ elif not hasattr (msg_expr , "identifier" ) and \
669
+ "identifier" in msg_expr and "name" in msg_expr ["identifier" ]:
670
+ self .path_name_queue .insert (0 , msg_expr ["identifier" ]["name" ])
671
+ path_name_added = True
672
+ exprs .append (msg_expr )
662
673
while self .cur_token_type_is (TokenType .COMMA ):
663
674
self .pos += 1
664
675
exprs .append (self ._expr ().get_message ())
665
676
self .consume_token (TokenType .RPAREN )
677
+ if path_name_added :
678
+ self .path_name_queue .pop ()
666
679
return exprs
667
680
668
681
def identifier (self ):
@@ -740,6 +753,8 @@ def document_field(self):
740
753
doc_path_item ["value" ] = self .consume_token (TokenType .IDENT )
741
754
col_id ["document_path" ].extend ([doc_path_item .get_message ()])
742
755
col_id ["document_path" ].extend (self .document_path ())
756
+ if self .path_name_queue :
757
+ col_id ["name" ] = self .path_name_queue [0 ]
743
758
expr = Message ("Mysqlx.Expr.Expr" )
744
759
expr ["type" ] = mysqlxpb_enum ("Mysqlx.Expr.Expr.Type.IDENT" )
745
760
expr ["identifier" ] = col_id
0 commit comments