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

Method parse_cases

parser/src/parser/parser.rs:763–790  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

761 }
762
763 fn parse_cases(&mut self) -> Result<Vec<MatchCase>, ParsingError> {
764 let mut cases = vec![];
765 loop {
766 if self.at(Kind::Dedent) || self.at(Kind::Eof) {
767 break;
768 }
769 let node = self.start_node();
770
771 // This identifier is case word
772 self.expect(Kind::Identifier)?;
773 let pattern = self.parse_patterns()?;
774 let guard = if self.at(Kind::If) {
775 Some(self.parse_guard()?)
776 } else {
777 None
778 };
779 self.expect(Kind::Colon)?;
780 let body = self.parse_suite()?;
781 cases.push(MatchCase {
782 node: self.finish_node(node),
783 pattern,
784 guard,
785 body,
786 });
787 }
788
789 Ok(cases)
790 }
791
792 fn parse_guard(&mut self) -> Result<Expression, ParsingError> {
793 self.expect(Kind::If)?;

Callers 1

parse_match_statementMethod · 0.80

Calls 7

atMethod · 0.80
start_nodeMethod · 0.80
expectMethod · 0.80
parse_patternsMethod · 0.80
parse_guardMethod · 0.80
parse_suiteMethod · 0.80
finish_nodeMethod · 0.80

Tested by

no test coverage detected