@@ -132,31 +132,44 @@ def group_identifier_list(tlist):
132132 [group_identifier_list (sgroup ) for sgroup in tlist .get_sublists ()
133133 if not isinstance (sgroup , (Identifier , IdentifierList ))]
134134 idx = 0
135- token = tlist .token_next_by_instance (idx , Identifier )
136- while token :
137- tidx = tlist .token_index (token )
138- end = tlist .token_not_matching (tidx + 1 ,
139- [lambda t : isinstance (t , Identifier ),
140- lambda t : t .is_whitespace (),
141- lambda t : t .match (T .Punctuation ,
142- ',' )
143- ])
144- if end is None :
145- end = tlist .tokens [- 1 ]
146- exclude_end = False
135+ # Allowed list items
136+ fend1_funcs = [lambda t : isinstance (t , Identifier ),
137+ lambda t : t .is_whitespace (),
138+ lambda t : t .ttype == T .Wildcard ,
139+ lambda t : t .match (T .Keyword , 'null' ),
140+ lambda t : t .ttype == T .Number .Integer ,
141+ lambda t : t .ttype == T .String .Single ,
142+ ]
143+ tcomma = tlist .token_next_match (idx , T .Punctuation , ',' )
144+ start = None
145+ while tcomma is not None :
146+ before = tlist .token_prev (tcomma )
147+ after = tlist .token_next (tcomma )
148+ # Check if the tokens around tcomma belong to a list
149+ bpassed = apassed = False
150+ for func in fend1_funcs :
151+ if before is not None and func (before ):
152+ bpassed = True
153+ if after is not None and func (after ):
154+ apassed = True
155+ if not bpassed or not apassed :
156+ # Something's wrong here, skip ahead to next ","
157+ start = None
158+ tcomma = tlist .token_next_match (tlist .token_index (tcomma )+ 1 ,
159+ T .Punctuation , ',' )
147160 else :
148- exclude_end = True
149- grp_tokens = tlist . tokens_between ( token , end ,
150- exclude_end = exclude_end )
151- while grp_tokens and ( grp_tokens [ - 1 ]. is_whitespace ()
152- or grp_tokens [ - 1 ]. match ( T . Punctuation , ',' )):
153- grp_tokens . pop ( )
154- if len ( grp_tokens ) <= 1 :
155- idx = tidx + 1
156- else :
157- group = tlist . group_tokens ( IdentifierList , grp_tokens )
158- idx = tlist . token_index ( group )
159- token = tlist . token_next_by_instance ( idx , Identifier )
161+ if start is None :
162+ start = before
163+ next_ = tlist . token_next ( after )
164+ if next_ is None or not next_ . match ( T . Punctuation , ',' ):
165+ # Reached the end of the list
166+ tokens = tlist . tokens_between ( start , after )
167+ group = tlist . group_tokens ( IdentifierList , tokens )
168+ start = None
169+ tcomma = tlist . token_next_match ( tlist . token_index ( group ) + 1 ,
170+ T . Punctuation , ',' )
171+ else :
172+ tcomma = next_
160173
161174
162175def group_parenthesis (tlist ):
0 commit comments