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

Method expect_and_consume

core/src/parser.rs:277–283  ·  view source on GitHub ↗

Expects the peeked token to be `t` and consumes it. Otherwise, leaves the token in the stream and fails with error `err`.

(&mut self, t: Token, err: E)

Source from the content-addressed store, hash-verified

275 /// Expects the peeked token to be `t` and consumes it. Otherwise, leaves the token in the
276 /// stream and fails with error `err`.
277 fn expect_and_consume<E: Into<String>>(&mut self, t: Token, err: E) -> Result<TokenSpan> {
278 let peeked = self.lexer.peek()?;
279 if peeked.token != t {
280 return Err(Error::Bad(peeked.pos, err.into()));
281 }
282 Ok(self.lexer.consume_peeked())
283 }
284
285 /// Expects the peeked token to be `t` and consumes it. Otherwise, leaves the token in the
286 /// stream and fails with error `err`, pointing at `pos` as the original location of the

Callers 7

parse_doMethod · 0.80
parse_if_multilineMethod · 0.80
parse_ifMethod · 0.80
parse_forMethod · 0.80
parse_onMethod · 0.80
parse_selectMethod · 0.80
parse_whileMethod · 0.80

Calls 2

consume_peekedMethod · 0.80
peekMethod · 0.45

Tested by

no test coverage detected