MCPcopy Create free account
hub / github.com/Glyphack/enderpy / parse_list

Method parse_list

parser/src/parser/parser.rs:1579–1613  ·  view source on GitHub ↗

https://docs.python.org/3/reference/expressions.html#list-displays

(&mut self)

Source from the content-addressed store, hash-verified

1577
1578 // https://docs.python.org/3/reference/expressions.html#list-displays
1579 fn parse_list(&mut self) -> Result<Expression, ParsingError> {
1580 let node = self.start_node();
1581 self.bump(Kind::LeftBrace);
1582 self.consume_whitespace_and_newline();
1583 if self.eat(Kind::RightBrace) {
1584 return Ok(Expression::List(Box::new(List {
1585 node: self.finish_node(node),
1586 elements: vec![],
1587 })));
1588 }
1589 let started_with_star = self.at(Kind::Mul);
1590 let first_elm = self.parse_star_named_expression()?;
1591 if !started_with_star
1592 && self.at(Kind::For)
1593 && (self.at(Kind::For)
1594 || self.at(Kind::Async) && matches!(self.peek_kind(), Ok(Kind::For)))
1595 {
1596 let generators = self.parse_comp_for()?;
1597 self.expect(Kind::RightBrace)?;
1598 return Ok(Expression::ListComp(Box::new(ListComp {
1599 node: self.finish_node(node),
1600 element: first_elm,
1601 generators,
1602 })));
1603 }
1604 self.bump(Kind::Comma);
1605 let rest = self.parse_starred_list(Kind::RightBrace)?;
1606 let elements = vec![first_elm];
1607 let elements = elements.into_iter().chain(rest).collect();
1608 self.expect(Kind::RightBrace)?;
1609 Ok(Expression::List(Box::new(List {
1610 node: self.finish_node(node),
1611 elements,
1612 })))
1613 }
1614
1615 // https://docs.python.org/3/reference/expressions.html#parenthesized-forms
1616 fn parse_paren_form_or_generator(&mut self) -> Result<Expression, ParsingError> {

Callers 1

parse_atomMethod · 0.80

Calls 13

ListClass · 0.85
ListCompClass · 0.85
start_nodeMethod · 0.80
bumpMethod · 0.80
eatMethod · 0.80
finish_nodeMethod · 0.80
atMethod · 0.80
parse_comp_forMethod · 0.80
expectMethod · 0.80
parse_starred_listMethod · 0.80

Tested by

no test coverage detected