Crates.io | laps_regex |
lib.rs | laps_regex |
version | 0.1.1 |
source | src |
created_at | 2023-06-17 14:00:32.8101 |
updated_at | 2023-12-24 11:10:59.351485 |
description | Tools for generating NFAs, DFAs and state-transition tables from regular expressions. |
homepage | |
repository | https://github.com/MaxXSoft/laps |
max_upload_size | |
id | 892909 |
size | 68,946 |
Tools for generating NFAs, DFAs and state-transition tables from regular expressions.
This library is built for crate laps
.
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);
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));
Copyright (C) 2022-2023 MaxXing. Licensed under either of Apache 2.0 or MIT at your option.