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

Method consume_operator

core/src/lexer.rs:433–464  ·  view source on GitHub ↗

Consumes the operator at the current position, whose first character is `first`.

(&mut self, first: CharSpan)

Source from the content-addressed store, hash-verified

431
432 /// Consumes the operator at the current position, whose first character is `first`.
433 fn consume_operator(&mut self, first: CharSpan) -> io::Result<TokenSpan> {
434 match (first.ch, self.input.peek()) {
435 (_, Some(Err(_))) => Err(self.input.next().unwrap().unwrap_err()),
436
437 ('<', Some(Ok(ch_span))) if ch_span.ch == '>' => {
438 self.input.next().unwrap()?;
439 Ok(TokenSpan::new(Token::NotEqual, first.pos, 2))
440 }
441
442 ('<', Some(Ok(ch_span))) if ch_span.ch == '=' => {
443 self.input.next().unwrap()?;
444 Ok(TokenSpan::new(Token::LessEqual, first.pos, 2))
445 }
446 ('<', Some(Ok(ch_span))) if ch_span.ch == '<' => {
447 self.input.next().unwrap()?;
448 Ok(TokenSpan::new(Token::ShiftLeft, first.pos, 2))
449 }
450 ('<', _) => Ok(TokenSpan::new(Token::Less, first.pos, 1)),
451
452 ('>', Some(Ok(ch_span))) if ch_span.ch == '=' => {
453 self.input.next().unwrap()?;
454 Ok(TokenSpan::new(Token::GreaterEqual, first.pos, 2))
455 }
456 ('>', Some(Ok(ch_span))) if ch_span.ch == '>' => {
457 self.input.next().unwrap()?;
458 Ok(TokenSpan::new(Token::ShiftRight, first.pos, 2))
459 }
460 ('>', _) => Ok(TokenSpan::new(Token::Greater, first.pos, 1)),
461
462 (_, _) => panic!("Should not have been called"),
463 }
464 }
465
466 /// Consumes the symbol or keyword at the current position, whose first letter is `first`.
467 ///

Callers 1

readMethod · 0.80

Calls 2

peekMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected