1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Contains parser and compiler options passed to rulex.
use crate::features::RulexFeatures;
/// Options passed to the rulex parser
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct ParseOptions {
/// The maximum number of digits in a `range` expression. Defaults to 6.
///
/// Note that if you increase this number, the time needed to compile a
/// rulex may increase exponentially. If you parse untrusted input, this
/// can be used for a DoS attack.
pub max_range_size: u8,
/// Allowed rulex features. By default, all features are allowed.
pub allowed_features: RulexFeatures,
}
impl Default for ParseOptions {
fn default() -> Self {
Self { max_range_size: 6, allowed_features: Default::default() }
}
}
/// Options passed to the rulex compiler
#[derive(Debug, Clone, Copy, Default)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct CompileOptions {
/// The targeted regex flavor. Rulex makes sure that the emitted regex is
/// compatible with this flavor.
pub flavor: RegexFlavor,
}
/// A regex flavor is a regex engine or a set of regex engines that are similar
/// enough that they can be treated the same for the purpose of writing regexes.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[non_exhaustive]
pub enum RegexFlavor {
/// PCRE and PCRE2
Pcre,
/// Python's `re` module
Python,
/// The `java.util.regex.Pattern` class
Java,
/// JavaScript (ECMAScript) built-in regular expressions
JavaScript,
/// .NET `Regex` class from the namespace `System.Text.RegularExpressions`
DotNet,
/// Ruby built-in regular expressions
Ruby,
/// The Rust `regex` crate
Rust,
}
impl Default for RegexFlavor {
fn default() -> Self {
RegexFlavor::Pcre
}
}