irongit

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

added the outer val

huncholanehuncholaneauthored
parent a2067c1commit d4ee5133aba85ef66ef7fd9238e1c546fe25dd15Browse files

4 files changed, +13 -4

+1-1.cargo/config.toml
@@ -1,4 +1,4 @@
11 [alias]
2-tr = "test --release"
32 e = "run --example"
43 b = "build"
4+t = "test --tests"
+3-3README.md
@@ -22,7 +22,7 @@ Allows for named groups in regular expressions to be generated from special file
2222 5. `iter_from_str(text: &str)` Extracts all the matches in a given string.
2323 6. `iter_from_file(filename: &str)` Extracts all the matches after opening the given filename.
2424
25-The abstract structure for matches within the regex_macro library contains `start_pos`, `end_pos`, and public fields for each named group inside of the `.re` file. Each field then contains a `start_pos`, `end_pos`, and `val` field.
25+The abstract structure for matches within the regex_folder_macro library contains `start_pos`, `end_pos`, and public fields for each named group inside of the `.re` file. Each field then contains a `start_pos`, `end_pos`, and `val` field.
2626
2727 ### Tips
2828
@@ -40,12 +40,12 @@ The abstract structure for matches within the regex_macro library contains `star
4040 ### event.rs
4141
4242 ```rust
43-use regex_macro::load_regex_files;
43+use regex_folder_macro::load_regex_files;
4444 // Loads the regular expressions within the folder named regex
4545 load_regex_files!("regex");
4646
4747 fn main() {
48- let events = EventRE::vec_from_file("tests/samples/events.txt").unwrap();
48+ let events = EventRE::vec_from_file("samples/events.txt").unwrap();
4949 println!("{}", serde_json::to_string_pretty(&events).unwrap());
5050 }
5151 ```
+3-0src/lib.rs
@@ -107,6 +107,7 @@ pub fn load_regex_files(input: TokenStream) -> TokenStream {
107107 pub struct #ident {
108108 pub start_pos: usize,
109109 pub end_pos: usize,
110+ pub val: String,
110111 #(#fields),*
111112 }
112113
@@ -126,6 +127,7 @@ pub fn load_regex_files(input: TokenStream) -> TokenStream {
126127 Some(Self {
127128 start_pos: captures.get(0).unwrap().start(),
128129 end_pos: captures.get(0).unwrap().end(),
130+ val: captures.get(0).unwrap().as_str().to_string(),
129131 #(#field_initializers),*
130132 })
131133 } else {
@@ -149,6 +151,7 @@ pub fn load_regex_files(input: TokenStream) -> TokenStream {
149151 Self {
150152 start_pos: captures.get(0).unwrap().start(),
151153 end_pos: captures.get(0).unwrap().end(),
154+ val: captures.get(0).unwrap().as_str().to_string(),
152155 #(#field_initializers),*
153156 }
154157 })
+6-0tests/test.rs
@@ -13,3 +13,9 @@ pub fn events_iter() {
1313 let events = EventRE::iter_from_file("./samples/events.txt").unwrap();
1414 assert_eq!(events.count(), 13);
1515 }
16+
17+#[test]
18+pub fn first_event() {
19+ let event = EventRE::from_file("samples/events.txt").unwrap().unwrap();
20+ assert_eq!(event.val, "7:30–8:00 AM Wake up + hydrate + light stretch");
21+}