MCPcopy Index your code
hub / github.com/endbasic/endbasic / parse_case_guards

Method parse_case_guards

core/src/parser.rs:1588–1681  ·  view source on GitHub ↗

Parses the guards after a `CASE` keyword.

(&mut self)

Source from the content-addressed store, hash-verified

1586
1587 /// Parses the guards after a `CASE` keyword.
1588 fn parse_case_guards(&mut self) -> Result<Vec<CaseGuardSpan>> {
1589 let mut guards = vec![];
1590
1591 loop {
1592 let peeked = self.lexer.peek()?;
1593 match peeked.token {
1594 Token::Else => {
1595 let token_span = self.lexer.consume_peeked();
1596
1597 if !guards.is_empty() {
1598 return Err(Error::Bad(
1599 token_span.pos,
1600 "CASE ELSE must be on its own".to_owned(),
1601 ));
1602 }
1603
1604 let peeked = self.lexer.peek()?;
1605 if peeked.token != Token::Eol && peeked.token != Token::Eof {
1606 return Err(Error::Bad(
1607 peeked.pos,
1608 "Expected newline after CASE ELSE".to_owned(),
1609 ));
1610 }
1611
1612 break;
1613 }
1614
1615 Token::Is => {
1616 self.lexer.consume_peeked();
1617
1618 let token_span = self.lexer.read()?;
1619 let rel_op = match token_span.token {
1620 Token::Equal => CaseRelOp::Equal,
1621 Token::NotEqual => CaseRelOp::NotEqual,
1622 Token::Less => CaseRelOp::Less,
1623 Token::LessEqual => CaseRelOp::LessEqual,
1624 Token::Greater => CaseRelOp::Greater,
1625 Token::GreaterEqual => CaseRelOp::GreaterEqual,
1626 _ => {
1627 return Err(Error::Bad(
1628 token_span.pos,
1629 "Expected relational operator".to_owned(),
1630 ));
1631 }
1632 };
1633
1634 let expr =
1635 self.parse_required_expr("Missing expression after relational operator")?;
1636 guards.push(CaseGuardSpan::Is(rel_op, expr));
1637 }
1638
1639 _ => {
1640 let from_expr = self.parse_required_expr("Missing expression in CASE guard")?;
1641
1642 let peeked = self.lexer.peek()?;
1643 match peeked.token {
1644 Token::Eol | Token::Comma => {
1645 guards.push(CaseGuardSpan::Is(CaseRelOp::Equal, from_expr));

Callers 1

parse_selectMethod · 0.80

Calls 6

consume_peekedMethod · 0.80
parse_required_exprMethod · 0.80
pushMethod · 0.80
peekMethod · 0.45
is_emptyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected