A rust macro that allows regular expression creation through independent files. Allows fully typed named groups.
moved samples out of test folder
6 files changed, +26 -6
+2-1README.md
| @@ -41,7 +41,8 @@ The abstract structure for matches within the regex_macro library contains `star | ||
| 41 | 41 | |
| 42 | 42 | ```rust |
| 43 | 43 | use regex_macro::load_regex_files; |
| 44 | -load_regex_files!("tests/regex"); | |
| 44 | +// Loads the regular expressions within the folder named regex | |
| 45 | +load_regex_files!("regex"); | |
| 45 | 46 | |
| 46 | 47 | fn main() { |
| 47 | 48 | let events = EventRE::vec_from_file("tests/samples/events.txt").unwrap(); |
+2-2examples/event.rs
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | use regex_folder_macro::load_regex_files; |
| 2 | 2 | |
| 3 | -load_regex_files!("tests/regex"); | |
| 3 | +load_regex_files!("regex"); | |
| 4 | 4 | |
| 5 | 5 | fn main() { |
| 6 | - let events = EventRE::vec_from_file("tests/samples/events.txt").unwrap(); | |
| 6 | + let events = EventRE::vec_from_file("samples/events.txt").unwrap(); | |
| 7 | 7 | println!("{}", serde_json::to_string_pretty(&events).unwrap()); |
| 8 | 8 | } |
+0-0tests/regex/Event.re → regex/Event.re
No content changes (mode or rename only).
+0-0tests/samples/events.txt → samples/events.txt
No content changes (mode or rename only).
+19-0src/lib.rs
| @@ -11,6 +11,25 @@ use syn::{parse_macro_input, Ident, LitStr}; | ||
| 11 | 11 | /// |
| 12 | 12 | /// - `m` (multi-line): `^` and `$` match the start and end of lines, not just the entire input. |
| 13 | 13 | /// - `x` (extended): allows whitespace and comments starting with `#` inside the regex. |
| 14 | +/// | |
| 15 | +/// Event Example: | |
| 16 | +/// ```text | |
| 17 | +/// ./ | |
| 18 | +/// # This will create a struct called EventRE with the fields start, end, ampm, and activity | |
| 19 | +/// | |
| 20 | +/// # Get the start | |
| 21 | +/// ^(?<start>\d{1,2}:\d{1,2}) | |
| 22 | +/// . | |
| 23 | +/// # Get the end time | |
| 24 | +/// (?<end>\d{1,2}:\d{1,2}) | |
| 25 | +/// \s{0,2} | |
| 26 | +/// | |
| 27 | +/// # Get the AM or PM after the times | |
| 28 | +/// (?<ampm>[AMPM]{2}) | |
| 29 | +/// . | |
| 30 | +/// # Get the activity string | |
| 31 | +/// (?<activity>.+) | |
| 32 | +/// ``` | |
| 14 | 33 | pub fn load_regex_files(input: TokenStream) -> TokenStream { |
| 15 | 34 | let folder_path = parse_macro_input!(input as LitStr).value(); |
| 16 | 35 |
+3-3tests/test.rs
| @@ -1,15 +1,15 @@ | ||
| 1 | 1 | use regex_folder_macro::load_regex_files; |
| 2 | 2 | |
| 3 | -load_regex_files!("./tests/regex"); | |
| 3 | +load_regex_files!("./regex"); | |
| 4 | 4 | |
| 5 | 5 | #[test] |
| 6 | 6 | pub fn events_vec() { |
| 7 | - let events = EventRE::vec_from_file("./tests/samples/events.txt"); | |
| 7 | + let events = EventRE::vec_from_file("./samples/events.txt"); | |
| 8 | 8 | assert!(events.unwrap().len() == 13); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | #[test] |
| 12 | 12 | pub fn events_iter() { |
| 13 | - let events = EventRE::iter_from_file("./tests/samples/events.txt").unwrap(); | |
| 13 | + let events = EventRE::iter_from_file("./samples/events.txt").unwrap(); | |
| 14 | 14 | assert_eq!(events.count(), 13); |
| 15 | 15 | } |