Parse whitespace CRITICAL: This function was the source of infinite loops in the original implementation PROBLEM: The original implementation used `map(take_while(...), |_| Token::Whitespace)` which would return Token::Whitespace even when no whitespace was found, causing the lexer to never advance and get stuck in an infinite loop. SOLUTION: Explicitly check if whitespace was consumed and retu
(input: &str)
| 1599 | /// 3. Function returns Error, allowing other parsers to try |
| 1600 | /// 4. simple_patterns() successfully parses "MATCH" |
| 1601 | fn whitespace(input: &str) -> IResult<&str, Token> { |
| 1602 | let (remaining, whitespace_chars) = take_while(|c: char| c.is_whitespace())(input)?; |
| 1603 | if whitespace_chars.is_empty() { |
| 1604 | return Err(nom::Err::Error(nom::error::Error::new( |
| 1605 | input, |
| 1606 | nom::error::ErrorKind::Tag, |
| 1607 | ))); |
| 1608 | } |
| 1609 | Ok((remaining, Token::Whitespace)) |
| 1610 | } |
| 1611 | |
| 1612 | /// Parse comments |
| 1613 | fn comment(input: &str) -> IResult<&str, &str> { |