Read an operator token, handling multi-character operators.
(&mut self)
| 307 | |
| 308 | /// Read an operator token, handling multi-character operators. |
| 309 | fn read_operator(&mut self) -> Token<'a> { |
| 310 | let start = self.position; |
| 311 | |
| 312 | // Get first character |
| 313 | let first = self.peek().unwrap(); |
| 314 | self.advance(); |
| 315 | |
| 316 | // Check for common multi-char operators |
| 317 | if let Some(second) = self.peek() { |
| 318 | let is_double = matches!( |
| 319 | (first, second), |
| 320 | // Comparison operators |
| 321 | (b'=', b'=') |
| 322 | | (b'!', b'=') |
| 323 | | (b'<', b'=') |
| 324 | | (b'>', b'=') |
| 325 | // Logical operators |
| 326 | | (b'&', b'&') |
| 327 | | (b'|', b'|') |
| 328 | // Increment/decrement |
| 329 | | (b'+', b'+') |
| 330 | | (b'-', b'-') |
| 331 | // Shift operators |
| 332 | | (b'<', b'<') |
| 333 | | (b'>', b'>') |
| 334 | // Arrow operators |
| 335 | | (b'-', b'>') |
| 336 | | (b'=', b'>') |
| 337 | // Scope operator |
| 338 | | (b':', b':') |
| 339 | // Compound assignment |
| 340 | | (b'+', b'=') |
| 341 | | (b'-', b'=') |
| 342 | | (b'*', b'=') |
| 343 | | (b'/', b'=') |
| 344 | | (b'%', b'=') |
| 345 | | (b'&', b'=') |
| 346 | | (b'|', b'=') |
| 347 | | (b'^', b'=') |
| 348 | ); |
| 349 | if is_double { |
| 350 | self.advance(); |
| 351 | |
| 352 | // Check for triple-char operators like <<= >>= |
| 353 | if let Some(third) = self.peek() { |
| 354 | let is_triple = matches!( |
| 355 | (first, second, third), |
| 356 | (b'<', b'<', b'=') | (b'>', b'>', b'=') |
| 357 | ); |
| 358 | if is_triple { |
| 359 | self.advance(); |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | Token::new( |
| 366 | &self.content[start..self.position], |