Skip to content

Commit 3ac4844

Browse files
authored
Improve dependencies (#8)
* Improve dependencies * remove temp test
1 parent 17d61ac commit 3ac4844

File tree

9 files changed

+82
-43
lines changed

9 files changed

+82
-43
lines changed

.github/workflows/rust.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919
- name: Build
20-
run: cargo build --verbose
20+
run: cargo build --all-features --verbose
2121
- name: Test & Lint
2222
run: |
23-
cargo test
24-
cargo clippy
23+
cargo test --all-features
24+
cargo clippy --all-features

Cargo.toml

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "regexsolver"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2021"
55
authors = ["Alexandre van Beurden"]
66
repository = "https://github.com/RegexSolver/regexsolver"
@@ -10,28 +10,40 @@ description = "Manipulate regex and automaton as if they were sets."
1010
readme = "README.md"
1111

1212
[dependencies]
13-
env_logger = "0.11.3"
14-
serde = "1.0.197"
15-
serde_derive = "1.0.197"
16-
serde_json = "1.0.114"
17-
ciborium = "0.2.2"
18-
z85 = "3.0.5"
19-
aes-gcm-siv = "0.11.1"
20-
sha2 = "0.10.8"
13+
serde = { version = "1.0", features = ["derive"], optional = true }
14+
ciborium = { version = "0.2.2", optional = true }
15+
z85 = { version = "3.0.5", optional = true }
16+
aes-gcm-siv = { version = "0.11.1", optional = true }
17+
sha2 = { version = "0.10.8", optional = true }
18+
flate2 = { version = "1.0.30", features = [
19+
"zlib-ng",
20+
], default-features = false, optional = true }
2121
nohash-hasher = "0.2"
2222
ahash = "0.8.11"
23-
regex-syntax = "0.8.5"
2423
log = "0.4.21"
2524
rand = "0.8.5"
2625
lazy_static = "1.4.0"
27-
flate2 = { version = "1.0.30", features = [
28-
"zlib-ng",
29-
], default-features = false }
3026
regex = "1.10.3"
31-
regex-charclass = { version = "1.0.3", features = ["serde"] }
27+
regex-syntax = "0.8.5"
28+
regex-charclass = { version = "1.0.3" }
3229

3330
[dev-dependencies]
3431
criterion = { version = "0.5", features = ["html_reports"] }
32+
env_logger = "0.11.3"
33+
serde_json = "1.0.114"
34+
35+
36+
[features]
37+
default = ["serde"]
38+
serde = [
39+
"regex-charclass/serde",
40+
"dep:serde",
41+
"dep:ciborium",
42+
"dep:z85",
43+
"dep:aes-gcm-siv",
44+
"dep:sha2",
45+
"dep:flate2",
46+
]
3547

3648
[[bench]]
3749
name = "my_benchmark"

src/cardinality/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use serde_derive::{Deserialize, Serialize};
1+
#[cfg(feature = "serde")]
2+
use serde::{Deserialize, Serialize};
23

34
/// Represent a number.
4-
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
5-
#[serde(tag = "type", content = "value")]
5+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6+
#[derive(PartialEq, Eq, Debug, Clone)]
7+
#[cfg_attr(feature = "serde", serde(tag = "type", content = "value"))]
68
pub enum Cardinality<U> {
79
/// An infinite number.
810
Infinite,

src/fast_automaton/convert/to_regex/mod.rs

+32-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
};
55

66
use ahash::{HashMapExt, HashSetExt};
7+
use log::warn;
78
use nohash_hasher::IntMap;
89

910
use crate::{error::EngineError, execution_profile::ThreadLocalParams, regex::RegularExpression};
@@ -258,28 +259,20 @@ impl FastAutomaton {
258259
Ok(automaton) => match self.is_equivalent_of(&automaton) {
259260
Ok(result) => {
260261
if !result {
261-
/*println!(
262-
"The automaton is not equivalent to the generated regex; automaton={} regex={}",
263-
serde_json::to_string(self).unwrap(),
264-
regex
265-
);*/
262+
warn!("The automaton is not equivalent to the generated regex; automaton={}, regex={}", self, regex);
266263
None
267264
} else {
268265
Some(regex)
269266
}
270267
}
271-
Err(_) => {
272-
//println!("{err}");
268+
Err(err) => {
269+
warn!("Engine error while checking for equivalence ({}); automaton={}, regex={}", err, self, regex);
273270
None
274271
}
275272
},
276273
Err(err) => {
277-
if let crate::error::EngineError::RegexSyntaxError(_) = err {
278-
/*error!(
279-
"The generated regex can not be converted to automaton to be checked for equivalence (Syntax Error); automaton={} regex={}",
280-
serde_json::to_string(self).unwrap(),
281-
regex
282-
);*/
274+
if let crate::error::EngineError::RegexSyntaxError(err) = err {
275+
warn!("The generated regex cannot be converted to automaton to be checked for equivalence ({}); automaton={}, regex={}", err, self, regex);
283276
}
284277
None
285278
}
@@ -422,8 +415,33 @@ mod tests {
422415
Ok(())
423416
}
424417

425-
/*#[test]
418+
#[test]
426419
fn test_convert_after_operation_4() -> Result<(), String> {
420+
let automaton1 = RegularExpression::new(".*abc.*")
421+
.unwrap()
422+
.to_automaton()
423+
.unwrap();
424+
let automaton2 = RegularExpression::new(".*def.*")
425+
.unwrap()
426+
.to_automaton()
427+
.unwrap();
428+
429+
let result = automaton1.intersection(&automaton2).unwrap();
430+
431+
let result = result.to_regex().unwrap();
432+
433+
assert_eq!(".*(abc.*def|def.*abc).*", result.to_string());
434+
435+
Ok(())
436+
}
437+
438+
/*#[test]
439+
fn test_convert_after_operation_5() -> Result<(), String> {
440+
if std::env::var_os("RUST_LOG").is_none() {
441+
std::env::set_var("RUST_LOG", "regexsolver=debug");
442+
}
443+
env_logger::init();
444+
427445
let automaton1 = RegularExpression::new(".*abc.*")
428446
.unwrap()
429447
.to_automaton()

src/fast_automaton/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::collections::hash_map::Entry;
77
use std::collections::VecDeque;
88
use std::fmt::Display;
99

10-
use crate::tokenizer::Tokenizer;
1110
use crate::{IntMap, IntSet};
1211

1312
pub(crate) type State = usize;
@@ -19,6 +18,7 @@ pub mod condition;
1918
mod convert;
2019
mod generate;
2120
mod operation;
21+
#[cfg(feature = "serde")]
2222
mod serializer;
2323
pub mod spanning_set;
2424

src/fast_automaton/serializer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use super::*;
22
use lazy_static::lazy_static;
33
use rand::Rng;
44
use serde::{de, ser, Deserializer, Serializer};
5-
use serde_derive::{Deserialize, Serialize};
5+
use serde::{Deserialize, Serialize};
66
use std::env;
77
use z85::{decode, encode};
8+
use crate::tokenizer::Tokenizer;
89

910
use sha2::{Digest, Sha256};
1011

src/fast_automaton/spanning_set/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use std::slice::Iter;
22

33
use ahash::AHashSet;
44
use regex_charclass::{char::Char, irange::RangeSet};
5+
#[cfg(feature = "serde")]
56
use serde::{Deserialize, Serialize};
67

78
/// Contains a set of [`RangeSet<Char>`] that span all the transition of a [`crate::FastAutomaton`].
8-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
9+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10+
#[derive(Clone, Debug, PartialEq, Eq)]
911
pub struct SpanningSet(Vec<RangeSet<Char>>, RangeSet<Char>);
1012

1113
impl SpanningSet {

src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use fast_automaton::FastAutomaton;
1111
use nohash_hasher::NoHashHasher;
1212
use regex::RegularExpression;
1313
use regex_charclass::{char::Char, irange::RangeSet};
14+
#[cfg(feature = "serde")]
1415
use serde::{Deserialize, Serialize};
1516

1617
pub mod cardinality;
@@ -27,12 +28,13 @@ type Range = RangeSet<Char>;
2728
/// Represents a term that can be either a regular expression or a finite automaton. This term can be manipulated with a wide range of operations.
2829
///
2930
/// To put constraint and limitation on the execution of operations please refer to [`execution_profile::ExecutionProfile`].
30-
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
31-
#[serde(tag = "type", content = "value")]
31+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
32+
#[derive(Clone, PartialEq, Eq, Debug)]
33+
#[cfg_attr(feature = "serde", serde(tag = "type", content = "value"))]
3234
pub enum Term {
33-
#[serde(rename = "regex")]
35+
#[cfg_attr(feature = "serde", serde(rename = "regex"))]
3436
RegularExpression(RegularExpression),
35-
#[serde(rename = "fair")]
37+
#[cfg_attr(feature = "serde", serde(rename = "fair"))]
3638
Automaton(FastAutomaton),
3739
}
3840

@@ -319,8 +321,9 @@ impl Term {
319321
}
320322

321323
/// Represents details about a [Term].
322-
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
323-
#[serde(tag = "type", rename = "details")]
324+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
325+
#[derive(Clone, PartialEq, Eq, Debug)]
326+
#[cfg_attr(feature = "serde", serde(tag = "type", rename = "details"))]
324327
pub struct Details {
325328
cardinality: Option<Cardinality<u32>>,
326329
length: (Option<u32>, Option<u32>),

src/regex/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use super::*;
1212
mod analyze;
1313
mod builder;
1414
mod operation;
15+
#[cfg(feature = "serde")]
1516
mod serializer;
1617

1718
/// Represent a regular expression.

0 commit comments

Comments
 (0)