rules/lib.rs
1#![allow(unused_variables)]
2#![allow(dead_code)]
3#![feature(slice_patterns)]
4
5//! # Rules
6//! Rules uses regular expressions to do pattern matching using syntax
7//! based upon the Perl 6 regex grammar. The Perl 6 grammar has been heavily
8//! revised from Perl 5 and should not be equated with it. This may look
9//! nothing like any regex you have seen before.
10//!
11//! # Note
12//!
13//! The only real currently available method is [`is_match()`]
14//! (re/struct.Regex.html#method.is_match).
15//!
16//! # Syntax
17//!
18//! Currently, this is designed for ASCII and may not behave properly
19//! with Unicode.
20//!
21//! Whitespace is generally ignored so that a regex can be more readable
22//! and less dense.
23//!
24//! ```plain
25//! r"fred" // Normal way
26//! r"f r e d" // Completely equivalent
27//! // Will match `apples_oranges` or any other deliminator
28//! r"apples . oranges"
29//! ```
30//!
31//! # Literals
32//!
33//! Alphanumerics, underscores (`_`), and everything enclosed within
34//! quotes (`"`) and ticks (`'`) are the only literals.
35//!
36//! ```plain
37//! hello_world // Matches `hello_world`.
38//! "carrot cake" // Matches `carrot cake`.
39//! 'apple pie' // Matches `apple pie`.
40//! ```
41//!
42//! Everything else must be escaped with a backslash (`\*`) to literally match.
43//!
44//! ```plain
45//! it\'s\ my\ birthday // Matches `it's my birthday`.
46//! ```
47//!
48//! # Chevrons: `<>`
49//!
50//! Chevrons are considered a metacharacter grouping operator whose behaviour
51//! changes depending on the first character found inside. The behavior for
52//! each different character is:
53//!
54//! First character | Example | Result
55//! ----------------|---------|-------
56//! Whitespace | `< big small >` | Alternative quotes matches `[ 'big' | 'small' ]`
57//! alphabetic | `<alpha>` | Named character class which capture
58//! `?` | `<?before foo>` | A positive zero width assertion
59//! `!` | `<!before foo>` | A negative zero width assertion
60//! `[` | `<[ ab ]>` | A character class matches `[ 'a' | 'b' ]`
61//! `-` | `<-[a] + [b]>` | Negated character class: `[ab]` negated
62//! `+` | `<+ [a] >` | Doesn't modify the class.
63//!
64//! # Lookaround
65//!
66//! * lookahead - `foo <?after bar>` matches `foo` in `foobar`
67//! * negative lookahead - `foo <!after bar>` matches `foo` in `foobaz`
68//! * lookbehind - `<?before foo> bar` matches `bar` in `foobar`
69//! * negative lookbehind - `<!before foo> bar` matches `bar` in `sushibar`
70//!
71//! An example with both:
72//! `<?before foo> bar <?after baz>` matches `bar` in `foobarbaz`
73//!
74//! # Set operators
75//!
76//! These operators can be applied to groups which will be analyzed later:
77//!
78//! ```plain
79//! + Union // [123] + [345] = [12345]
80//! | Union // Same
81//! & Intersection // [123] & [345] = [3]
82//! - Difference // [123] - [345] = [12]
83//! ^ Symmetric difference // [123] ^ [345] = [1245]
84//! ```
85//!
86//! # Character classes
87//!
88//! ## Default character classes
89//!
90//! Character | Matches | Inverse
91//! ----------|-----------------------|--------
92//! `.` | Any character | N/A
93//! `\d` | Digit | `\D`
94//! `\h` | Horizontal whitespace | `\H`
95//! `\n` | Newline | `\N`
96//! `\s` | Any whitespace | `\S`
97//! `\t` | Tab | `\T`
98//! `\w` | Alphanumeric or `_` | `\W`
99//!
100//! ## Custom character classes
101//!
102//! Characters inside a set of `<[ ]>` form a custom character
103//! class:
104//!
105//! ```plain
106//! // Matches `a` or `b` or `c`
107//! <[ a b c ]>
108//!
109//! // `..` expresses a range so this matches
110//! // from `a` to `g` or a digit
111//! <[ a .. g \d ]>
112//!
113//! // The `[]` bind the sets together into (non-capturing)
114//! // groups so set operators can be used.
115//! <[0-9] - [13579]> // Matches an even number
116//! <\d - [13579]> // Same
117//! ```
118//!
119//! # Comments
120//!
121//! Comments are allowed inside a regex.
122//!
123//! ```plain
124//! // This matches `myregex`
125//! r"my // This is a comment which goes to the end of the line
126//! regex"
127//! ```
128
129#[doc(hidden)] pub mod collapse;
130#[doc(hidden)] pub mod parse;
131#[doc(hidden)] pub mod range_set;
132#[doc(hidden)] pub mod unicode;
133
134pub mod re;