(&mut self)
| 413 | } |
| 414 | |
| 415 | fn consume_global_variable_name(&mut self) -> Result<Token, Box<Diagnostic>> { |
| 416 | let start_index = self.index; |
| 417 | |
| 418 | // Advance `@` |
| 419 | self.advance(); |
| 420 | |
| 421 | // Make sure first character is alphabetic |
| 422 | if !self.is_current_char_func(|c| c.is_alphanumeric()) { |
| 423 | return Err(Diagnostic::error( |
| 424 | "Global variable name must start with alphabetic character", |
| 425 | ) |
| 426 | .add_help("Add at least one alphabetic character after @") |
| 427 | .with_location(self.current_source_location()) |
| 428 | .as_boxed()); |
| 429 | } |
| 430 | |
| 431 | while self.is_current_char_func(|c| c == '_' || c.is_alphanumeric()) { |
| 432 | self.advance(); |
| 433 | } |
| 434 | |
| 435 | // Identifier is being case-insensitive by default, convert to lowercase to be easy to compare and lookup |
| 436 | let literal = &self.content[start_index..self.index]; |
| 437 | let mut string: String = literal.iter().collect(); |
| 438 | string = string.to_lowercase(); |
| 439 | |
| 440 | let location = self.current_source_location(); |
| 441 | Ok(Token::new(TokenKind::GlobalVariable(string), location)) |
| 442 | } |
| 443 | |
| 444 | fn consume_identifier(&mut self) -> Token { |
| 445 | let start_index = self.index; |
no test coverage detected