#parser #parser-combinators #regex

nom-regex

regular expressions for nom parsers

2 unstable releases

0.2.0 Aug 21, 2021
0.1.0 Jul 25, 2021

#11 in #parser-combinators

Download history 2/week @ 2021-09-26 30/week @ 2021-10-03 42/week @ 2021-10-10 96/week @ 2021-10-17 45/week @ 2021-10-24 35/week @ 2021-10-31 46/week @ 2021-11-07 13/week @ 2021-11-14 75/week @ 2021-11-21 10/week @ 2021-11-28 68/week @ 2021-12-05 1766/week @ 2021-12-12 944/week @ 2021-12-19 1008/week @ 2021-12-26 2042/week @ 2022-01-02 3033/week @ 2022-01-09

7,094 downloads per month

MIT license

25KB
470 lines

nom-regex

This crate provides combinators for nom parser combinators using the regex crate.

Example

use nom::{Err, error::ErrorKind};
use nom_regex::str::re_match;
fn main() {
  let re = regex::Regex::new(r"^\d{4}").unwrap();
  let parser = re_match::<(&str, ErrorKind)>(re);
  assert_eq!(parser("2019"), Ok(("", "2019")));
  assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::RegexpMatch))));
  assert_eq!(parser("2019-10"), Ok(("", "2019-10")));
}

lib.rs:

Parser combinators that use regular expressions.

This crate provides combinators for nom parser combinators using the regex crate.

Example

use nom::{Err, error::ErrorKind};
use nom_regex::str::re_match;
fn main() {
  let re = regex::Regex::new(r"^\d{4}").unwrap();
  let parser = re_match::<(&str, ErrorKind)>(re);
  assert_eq!(parser("2019"), Ok(("", "2019")));
  assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::RegexpMatch))));
  assert_eq!(parser("2019-10"), Ok(("", "2019-10")));
}

Dependencies

~2MB
~55K SLoC