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

Method consume_label

core/src/lexer.rs:602–634  ·  view source on GitHub ↗

Consumes the label definition at the current position.

(&mut self, first: CharSpan)

Source from the content-addressed store, hash-verified

600
601 /// Consumes the label definition at the current position.
602 fn consume_label(&mut self, first: CharSpan) -> io::Result<TokenSpan> {
603 let mut s = String::new();
604
605 match self.input.peek() {
606 Some(Ok(ch_span)) => match ch_span.ch {
607 ch if ch.is_word() && !ch.is_numeric() => s.push(self.input.next().unwrap()?.ch),
608 _ch => (),
609 },
610 Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()),
611 None => (),
612 }
613 if s.is_empty() {
614 return Ok(TokenSpan::new(Token::Bad("Empty label name".to_owned()), first.pos, 1));
615 }
616
617 loop {
618 match self.input.peek() {
619 Some(Ok(ch_span)) => match ch_span.ch {
620 ch if ch.is_word() => s.push(self.input.next().unwrap()?.ch),
621 ch if ch.is_separator() => break,
622 ch => {
623 let msg = format!("Unexpected character in label: {}", ch);
624 return self.handle_bad_read(msg, first.pos);
625 }
626 },
627 Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()),
628 None => break,
629 }
630 }
631
632 let token_len = s.len() + 1;
633 Ok(TokenSpan::new(Token::Label(s), first.pos, token_len))
634 }
635
636 /// Consumes the remainder of the line and returns the token that was encountered at the end
637 /// (which may be EOF or end of line).

Callers 1

readMethod · 0.80

Calls 8

is_wordMethod · 0.80
pushMethod · 0.80
is_separatorMethod · 0.80
handle_bad_readMethod · 0.80
peekMethod · 0.45
nextMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected