Function lip::take_chomped

source ·
pub fn take_chomped<'a, P, S: Clone + 'a>(
    parser: P
) -> impl Parser<'a, Output = String, State = S>where
    P: Parser<'a, State = S> + 'a,
Expand description

Take the chomped string from a bunch of chompers.

Sometimes parsers like int or variable cannot do exactly what you need. The “chomping” family of functions is meant for that case! Maybe you need to parse valid PHP variables like $x and $txt:

fn php_variable<'a, S: Clone + 'a>() -> impl Parser<'a, Output = String, State = S> {
  take_chomped(succeed!()
    .skip(chomp_ifc(|c: char| c == '$', "a '$'"))
    .skip(chomp_ifc(|c: char| c.is_alphabetic() || c == '_', "a letter or a '_'"))
    .skip(chomp_while0c(|c: char| c.is_alphanumeric() || c == '_', "a letter, digit, or '_'"))
  )
}