#1866·nom

`// C++/EOL-style comments` recipe does not seem to work

Author: nyurikCreated Oct 1, 2025Updated Mar 19, 2026

The // C++/EOL-style comments recipe seems to not match the expected content. The expected parser here should accept //...\n, whereas the example for some reason works with a single char '%'. Moreover, ideally I would like an example that requires a newline with an optional end-of-line comment before that. Am I misreading it?

rust
/// This version uses % to start a comment, does not consume the newline character, and returns an output of ().
pub fn peol_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E>
{
  value(
    (), // Output is thrown away.
    pair(char('%'), is_not("\n\r"))
  ).parse(i)
}