Crates.io | nom-regex |
lib.rs | nom-regex |
version | 0.2.0 |
source | src |
created_at | 2021-07-25 15:53:38.658761 |
updated_at | 2021-08-21 11:11:32.521544 |
description | regular expressions for nom parsers |
homepage | |
repository | |
max_upload_size | |
id | 427102 |
size | 26,260 |
This crate provides combinators for nom parser combinators using the regex crate.
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")));
}