(&mut self)
| 406 | } |
| 407 | |
| 408 | fn parse_path(&mut self) -> Result<(String, Vec<String>), String> { |
| 409 | let mut path = String::new(); |
| 410 | let mut params = Vec::new(); |
| 411 | |
| 412 | // Handle leading slash |
| 413 | if self.check(TokenType::Slash) { |
| 414 | path.push('/'); |
| 415 | self.advance(); |
| 416 | } |
| 417 | |
| 418 | while !self.is_at_end() { |
| 419 | match self.current.kind { |
| 420 | TokenType::Slash => { |
| 421 | path.push('/'); |
| 422 | self.advance(); |
| 423 | } |
| 424 | TokenType::Colon => { |
| 425 | self.advance(); // Consume : |
| 426 | |
| 427 | // Parse parameter name |
| 428 | if !self.check(TokenType::Identifier) { |
| 429 | return Err("Expected parameter name after ':'".to_string()); |
| 430 | } |
| 431 | let name = self.current.lexeme.to_string(); |
| 432 | self.advance(); |
| 433 | |
| 434 | // Add parameter to path in the format Axum expects: {id} |
| 435 | path.push('{'); |
| 436 | path.push_str(&name); |
| 437 | path.push('}'); |
| 438 | |
| 439 | // Add parameter name to our list |
| 440 | params.push(name); |
| 441 | } |
| 442 | TokenType::Identifier => { |
| 443 | path.push_str(self.current.lexeme); |
| 444 | self.advance(); |
| 445 | } |
| 446 | TokenType::Minus => { |
| 447 | path.push('-'); |
| 448 | self.advance(); |
| 449 | } |
| 450 | TokenType::OpenBrace | TokenType::Comma => break, |
| 451 | _ => return Err(format!("Unexpected token in path: {:?}", self.current.kind)), |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | Ok((path, params)) |
| 456 | } |
| 457 | fn consume(&mut self, expected: TokenType, message: &str) -> Result<(), String> { |
| 458 | if self.check(expected) { |
| 459 | self.advance(); |
no test coverage detected