MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / scan_identifier

Method scan_identifier

aiscript-lexer/src/lib.rs:416–462  ·  view source on GitHub ↗

Scans identifiers and keywords

(&mut self)

Source from the content-addressed store, hash-verified

414
415 // Scans identifiers and keywords
416 fn scan_identifier(&mut self) -> Token<'a> {
417 while matches!(self.peek(), Some(c) if c.is_alphanumeric() || c == '_') {
418 self.advance();
419 }
420
421 // Check for ! after identifier for error types
422 if self.peek() == Some('!') {
423 self.advance();
424 // The lexeme will include the !.
425 return self.make_token(TokenType::Error);
426 }
427
428 let text = &self.source[self.start..self.current];
429 let kind = match text {
430 "ai" => TokenType::AI,
431 "agent" => TokenType::Agent,
432 "and" => TokenType::And,
433 "break" => TokenType::Break,
434 "class" => TokenType::Class,
435 "const" => TokenType::Const,
436 "continue" => TokenType::Continue,
437 "else" => TokenType::Else,
438 "enum" => TokenType::Enum,
439 "false" => TokenType::False,
440 "for" => TokenType::For,
441 "fn" => TokenType::Fn,
442 "if" => TokenType::If,
443 "in" => TokenType::In,
444 "match" => TokenType::Match,
445 "nil" => TokenType::Nil,
446 "not" => TokenType::Not,
447 "or" => TokenType::Or,
448 "prompt" => TokenType::Prompt,
449 "pub" => TokenType::Pub,
450 "return" => TokenType::Return,
451 "raise" => TokenType::Raise,
452 "super" => TokenType::Super,
453 "self" => TokenType::Self_,
454 "true" => TokenType::True,
455 "let" => TokenType::Let,
456 "use" => TokenType::Use,
457 "while" => TokenType::While,
458 _ => TokenType::Identifier,
459 };
460
461 self.make_token(kind)
462 }
463
464 // Scans the next token from the source
465 fn scan_token(&mut self) -> Token<'a> {

Callers 1

scan_tokenMethod · 0.80

Calls 3

advanceMethod · 0.80
make_tokenMethod · 0.80
peekMethod · 0.45

Tested by

no test coverage detected