MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_pattern

Method parse_pattern

cranelift/isle/isle/src/parser.rs:864–910  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

862 }
863
864 fn parse_pattern(&mut self) -> Result<Pattern> {
865 let pos = self.pos();
866 if self.is_int() {
867 Ok(Pattern::ConstInt {
868 val: self.expect_int()?,
869 pos,
870 })
871 } else if self.is_const() {
872 let val = self.parse_const()?;
873 Ok(Pattern::ConstPrim { val, pos })
874 } else if self.eat_sym_str("_")? {
875 Ok(Pattern::Wildcard { pos })
876 } else if self.eat_sym_str("true")? {
877 Ok(Pattern::ConstBool { val: true, pos })
878 } else if self.eat_sym_str("false")? {
879 Ok(Pattern::ConstBool { val: false, pos })
880 } else if self.is_sym() {
881 let var = self.parse_ident()?;
882 if self.is_at() {
883 self.expect_at()?;
884 let subpat = Box::new(self.parse_pattern()?);
885 Ok(Pattern::BindPattern { var, subpat, pos })
886 } else {
887 Ok(Pattern::Var { var, pos })
888 }
889 } else if self.is_lparen() {
890 self.expect_lparen()?;
891 if self.eat_sym_str("and")? {
892 let mut subpats = vec![];
893 while !self.is_rparen() {
894 subpats.push(self.parse_pattern()?);
895 }
896 self.expect_rparen()?;
897 Ok(Pattern::And { subpats, pos })
898 } else {
899 let sym = self.parse_ident()?;
900 let mut args = vec![];
901 while !self.is_rparen() {
902 args.push(self.parse_pattern()?);
903 }
904 self.expect_rparen()?;
905 Ok(Pattern::Term { sym, args, pos })
906 }
907 } else {
908 Err(self.error(pos, "Unexpected pattern".into()))
909 }
910 }
911
912 fn parse_iflet_or_expr(&mut self) -> Result<IfLetOrExpr> {
913 let pos = self.pos();

Callers 3

parse_etorMethod · 0.80
parse_ruleMethod · 0.80
parse_ifletMethod · 0.80

Calls 15

OkFunction · 0.85
expect_intMethod · 0.80
parse_constMethod · 0.80
eat_sym_strMethod · 0.80
parse_identMethod · 0.80
is_atMethod · 0.80
expect_atMethod · 0.80
is_lparenMethod · 0.80
expect_lparenMethod · 0.80
is_rparenMethod · 0.80
expect_rparenMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected