laps_regex

Crates.iolaps_regex
lib.rslaps_regex
version0.1.1
sourcesrc
created_at2023-06-17 14:00:32.8101
updated_at2023-12-24 11:10:59.351485
descriptionTools for generating NFAs, DFAs and state-transition tables from regular expressions.
homepage
repositoryhttps://github.com/MaxXSoft/laps
max_upload_size
id892909
size68,946
MaxXing (MaxXSoft)

documentation

https://docs.rs/laps_regex

README

laps_regex

Tools for generating NFAs, DFAs and state-transition tables from regular expressions.

This library is built for crate laps.

Example: Matching UTF-8 Strings

use laps_regex::re::{RegexBuilder, CharsMatcher};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum Token {
  Keyword,
  Identifier,
  Number,
}

let matcher: CharsMatcher<_> = RegexBuilder::new()
  .add("if|else|while", Token::Keyword)
  .add("[_a-zA-Z][_a-zA-Z0-9]*", Token::Identifier)
  .add("[0-9]|[1-9][0-9]+", Token::Number)
  .build()
  .unwrap();

assert_eq!(matcher.is_str_match("if"), Some(&Token::Keyword));
assert_eq!(matcher.is_str_match("while1"), Some(&Token::Identifier));
assert_eq!(matcher.is_str_match("42"), Some(&Token::Number));
assert_eq!(matcher.is_str_match("?"), None);

Example: Matching Bytes

use laps_regex::re::{RegexBuilder, BytesMatcher};

let matcher: BytesMatcher<_> = RegexBuilder::new()
  .add("hello|hi", 0)
  .add("goodbye|bye", 1)
  .build_bytes()
  .unwrap();

assert_eq!(matcher.is_match(b"hello"), Some(&0));
assert_eq!(matcher.is_match(&[0x62, 0x79, 0x65]), Some(&1));

License

Copyright (C) 2022-2023 MaxXing. Licensed under either of Apache 2.0 or MIT at your option.

Commit count: 528

cargo fmt