Function chumsky::text::newline

source ·
pub fn newline<'a, C: Character + 'a, E: Error<C> + 'a>(
    
) -> impl Parser<C, (), Error = E> + Copy + Clone + 'a
Expand description

A parser that accepts (and ignores) any newline characters or character sequences.

The output type of this parser is ().

This parser is quite extensive, recognising:

  • Line feed (\n)
  • Carriage return (\r)
  • Carriage return + line feed (\r\n)
  • Vertical tab (\x0B)
  • Form feed (\x0C)
  • Next line (\u{0085})
  • Line separator (\u{2028})
  • Paragraph separator (\u{2029})

Examples

let newline = text::newline::<char, Simple<char>>()
    .then_ignore(end());

assert_eq!(newline.parse("\n"), Ok(()));
assert_eq!(newline.parse("\r"), Ok(()));
assert_eq!(newline.parse("\r\n"), Ok(()));
assert_eq!(newline.parse("\x0B"), Ok(()));
assert_eq!(newline.parse("\x0C"), Ok(()));
assert_eq!(newline.parse("\u{0085}"), Ok(()));
assert_eq!(newline.parse("\u{2028}"), Ok(()));
assert_eq!(newline.parse("\u{2029}"), Ok(()));