Changeset - 1e7b35645ea4
[Not reviewed]
default
1 5 1
Laman - 9 months ago 2024-07-09 14:07:29

renamed the package to regular-expresso
6 files changed with 10 insertions and 9 deletions:
0 comments (0 inline, 0 general)
Cargo.lock
Show inline comments
 
# This file is automatically @generated by Cargo.
 
# It is not intended for manual editing.
 
version = 3
 

	
 
[[package]]
 
name = "regexp"
 
name = "regular-expresso"
 
version = "1.0.0"
Cargo.toml
Show inline comments
 
[package]
 
name = "regexp"
 
name = "regular-expresso"
 
version = "1.0.0"
 
edition = "2021"
 
license = " GPL-3.0-or-later"
 

	
 
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
README.md
Show inline comments
 
@@ -13,22 +13,25 @@ The supported syntax is restricted to th
 
Licensed under GNU GPLv3 or newer.
 

	
 
## Usage
 
The python code supports Python 3.9 and higher. The rust code is written for Rust edition 2021.
 

	
 
```
 
# If you want to use Rust, compile it first
 
cargo build --release
 

	
 
# Match a string against a pattern (returns true or false)
 
python regexp.py match PATTERN STRING
 
python regular-expresso.py match PATTERN STRING
 
# or
 
cargo run match PATTERN STRING
 
./target/release/regular-expresso match PATTERN STRING
 

	
 
# Compare two regexps and return None of they are equivalent, or the shortest string that can distinguish them
 
# That is, it gets accepted by one, but not the other
 
python regexp.py compare PATTERN1 PATTERN2
 
# or
 
cargo run compare PATTERN1 PATTERN2
 
./target/release/regular-expresso compare PATTERN1 PATTERN2
 
```
 

	
 
## Theory
 
1. The pattern gets parsed into a tree of its parts.
 
2. We check which symbols can stand at the beginning, which can follow each other and which can stand at the end of the string. These data are used to construct a non-deterministic finite automaton (NFA).
 
3. *Determinization:* We explore the possible paths through the NFA, recording the state sets visited. Each set is then converted to a single state of a deterministic finite automaton (DFA).
regular-expresso.py
Show inline comments
 
file renamed from regexp.py to regular-expresso.py
src/main.rs
Show inline comments
 
use std::env;
 
use regexp::RegexpDFA;
 
use regular_expresso::RegexpDFA;
 

	
 
fn test() {
 
	let tests = ["", "a", "ab", "aabb", "abab", "abcd", "abcbcdbcd"];
 
	for pattern in ["a(b|c)", "a*b*", "(ab)*", "a((bc)*d)*", "(a|b)*a(a|b)(a|b)(a|b)", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] {
 
		println!("# {pattern}");
 
		match RegexpDFA::new(&pattern.to_string()) {
tests/test_regexp.rs
Show inline comments
 
use regexp::RegexpNFA;
 
use regexp::RegexpDFA;
 
use regexp::ParsingError;
 
use regular_expresso::{RegexpNFA, RegexpDFA, ParsingError};
 

	
 
#[test]
 
fn test_eval_basic_nfa() {
 
	let r = RegexpNFA::new(&String::from("abc")).unwrap();
 
	assert!(r.eval(String::from("abc")));
 
	assert!(!r.eval(String::from("ab")));
0 comments (0 inline, 0 general)