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

Method expect_and_consume_with_pos

core/src/parser.rs:288–300  ·  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`, pointing at `pos` as the original location of the problem.

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

Source from the content-addressed store, hash-verified

286 /// stream and fails with error `err`, pointing at `pos` as the original location of the
287 /// problem.
288 fn expect_and_consume_with_pos<E: Into<String>>(
289 &mut self,
290 t: Token,
291 pos: LineCol,
292 err: E,
293 ) -> Result<()> {
294 let peeked = self.lexer.peek()?;
295 if peeked.token != t {
296 return Err(Error::Bad(pos, err.into()));
297 }
298 self.lexer.consume_peeked();
299 Ok(())
300 }
301
302 /// Reads statements until the `delim` keyword is found. The delimiter is not consumed.
303 fn parse_until(&mut self, delim: Token) -> Result<Vec<Statement>> {

Callers 8

parse_doMethod · 0.80
parse_if_multilineMethod · 0.80
reset_ifMethod · 0.80
parse_forMethod · 0.80
parse_callable_bodyMethod · 0.80
parse_selectMethod · 0.80
reset_selectMethod · 0.80
parse_whileMethod · 0.80

Calls 2

consume_peekedMethod · 0.80
peekMethod · 0.45

Tested by

no test coverage detected