irongit

A rust macro that allows regular expression creation through independent files. Allows fully typed named groups.

moved samples out of test folder

huncholanehuncholaneauthored
parent 9754136commit 5423d787d3b843b9b36f248e67dfa2645301e24fBrowse files

6 files changed, +26 -6

+2-1README.md
@@ -41,7 +41,8 @@ The abstract structure for matches within the regex_macro library contains `star
4141
4242 ```rust
4343 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");
4546
4647 fn main() {
4748 let events = EventRE::vec_from_file("tests/samples/events.txt").unwrap();
+2-2examples/event.rs
@@ -1,8 +1,8 @@
11 use regex_folder_macro::load_regex_files;
22
3-load_regex_files!("tests/regex");
3+load_regex_files!("regex");
44
55 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();
77 println!("{}", serde_json::to_string_pretty(&events).unwrap());
88 }
+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};
1111 ///
1212 /// - `m` (multi-line): `^` and `$` match the start and end of lines, not just the entire input.
1313 /// - `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+/// ```
1433 pub fn load_regex_files(input: TokenStream) -> TokenStream {
1534 let folder_path = parse_macro_input!(input as LitStr).value();
1635
+3-3tests/test.rs
@@ -1,15 +1,15 @@
11 use regex_folder_macro::load_regex_files;
22
3-load_regex_files!("./tests/regex");
3+load_regex_files!("./regex");
44
55 #[test]
66 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");
88 assert!(events.unwrap().len() == 13);
99 }
1010
1111 #[test]
1212 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();
1414 assert_eq!(events.count(), 13);
1515 }