nom-both 0.1.1

Extension of nom to provide special both_ parsers
Documentation
  • Coverage
  • 20%
    1 out of 5 items documented1 out of 5 items with examples
  • Size
  • Source code size: 7.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.27 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 21s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dalance/nom-both
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dalance

nom-both is an extension of nom to provide special both_ parser.

Examples

The following example show a quick example.

use nom::branch::*;
use nom::bytes::complete::*;
use nom::IResult;
use nom_both::both_parser;

#[both_parser]
pub fn both_opt_parser(s: &str) -> IResult<&str, Option<&str>> {
    let (s, _) = tag("1")(s)?;
    let (s, x) = both_opt(tag("2"))(s)?;
    let (s, _) = tag("2")(s)?;
    let (s, _) = tag("3")(s)?;
    Ok((s, x))
}

#[both_parser]
pub fn both_alt_parser(s: &str) -> IResult<&str, &str> {
    let (s, _) = tag("1")(s)?;
    let (s, x) = both_alt(tag("22"), tag("2"))(s)?;
    let (s, _) = tag("2")(s)?;
    let (s, _) = tag("3")(s)?;
    Ok((s, x))
}

fn main() {
    let ret = both_opt_parser("123");
    assert_eq!("None", format!("{:?}", ret.unwrap().1));

    let ret = both_alt_parser("1223");
    assert_eq!("\"2\"", format!("{:?}", ret.unwrap().1));
}