@@ -412,8 +412,32 @@ def _parse_parens_or(self, idx: int) -> tuple[AnyNode, int]:
412412 idx = self ._expect_cls_consume (
413413 idx , RParToken , f"Expected ')' at end of expr, got { self [idx ].name } " )
414414 return ParenNode (self .tok_region (start , idx ), None , [inner ]), idx
415+ elif isinstance (self [idx ], LSqBracket ):
416+ return self ._parse_list_literal (idx )
415417 return self ._parse_atom_or_autocat (idx )
416418
419+ def _parse_list_literal (self , idx : int ) -> tuple [AnyNode , int ]:
420+ start = idx
421+ assert self .matches (idx , LSqBracket )
422+ idx += 1
423+ if self .matches (idx , RSqBracket ):
424+ idx += 1 # simple case, no args
425+ return ListNode (self .tok_region (start , idx )), idx
426+ arg1 , idx = self ._parse_expr (idx )
427+ args = [arg1 ]
428+ while not self .matches (idx , RSqBracket ):
429+ if not self .matches (idx , CommaToken ): # if not end, must be comma
430+ raise self .err (f"Expected ',' or ']' after item in list"
431+ f" literal, got { self [idx ].name } " , self [idx ])
432+ idx += 1
433+ if self .matches (idx , RSqBracket ): # trailing comma, no value
434+ break
435+ arg , idx = self ._parse_expr (idx )
436+ args .append (arg )
437+ assert self .matches (idx , RSqBracket )
438+ idx += 1
439+ return ListNode (self .tok_region (start , idx ), None , args ), idx
440+
417441 def _parse_basic_item (self , idx : int ):
418442 left , new_idx = self ._parse_parens_or (idx )
419443 while idx != (idx := new_idx ): # If progress made, set old to current and loop again
@@ -476,7 +500,8 @@ def _parse_pow_or(self, idx: int) -> tuple[AnyNode, int]:
476500 idx += 1
477501 # parse_unary_or -> parse_pow_or -> parse_unary_or -> parse_pow_or
478502 # This is right-recursion so is fine as progress will be made each call to get here
479- return self ._parse_unary_or (idx )
503+ right , idx = self ._parse_unary_or (idx )
504+ return self .node_from_children (PowNode , [leftmost , right ]), idx
480505
481506 def _parse_unary_or (self , idx : int ) -> tuple [AnyNode , int ]:
482507 unaries , idx = self ._parse_unaries_into_tok_list (idx )
0 commit comments