#regex #regex-parser #set

re-set

Regular expression set parser at run time

7 releases

0.2.0 Apr 17, 2023
0.1.1 Apr 6, 2023
0.1.0 Mar 4, 2023
0.0.3 Feb 11, 2023

#221 in Parser tooling

39 downloads per month
Used in re-set-macros

Apache-2.0

12KB
222 lines

re-set

Regular expression set parser at compile and run time.

Macro usage

use re_set_macros::find;

find!(fn find_identifier "[_[:alpha:]][[:word:]]*");

assert_eq!(find_identifier("foo bar"), Some((0, "foo")));
use re_set_macros::find;

find!(pub fn match_string
  // Single quotes
  r"'(\\'|.)*?'",
  // Double quotes
  r#""(\\"|.)*?""#,
  // Multi-line strings
  r"(?s)`(\\`|.)*?`"
);

let (_, string) = match_string(r#""Hello, world!""#).unwrap();

assert_eq!(string, r#""Hello, world!""#);
use re_set_macros::find;

find!(pub(crate) fn next_token
  // 0: Punctuation
  "[[:punct:]]+",
  // 1: Words
  "[[:word:]]+",
  // 2: Whitespace
  "[[:space:]]+"
);

let result = next_token("foo bar");

assert_eq!(result, Some((1, "foo")));

let (index, token) = result.unwrap();

match index {
  0 => println!("Found punctuation: {token}"),
  1 => println!("Found word: {token}"),
  2 => println!("Found whitespace: {token}"),
  _ => unreachable!(),
}

lib.rs:

A regex parser and compiler.

Dependencies

~2.2–3MB
~55K SLoC