irongit

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

improve docstrings

huncholanehuncholaneauthored
parent 65bbb42commit 8228dec8c79dbcc1a7d559611b3bbd5ea0217163Browse files

3 files changed, +18 -1

+6-1README.md
@@ -6,7 +6,12 @@ Allows for named groups in regular expressions to be generated from special file
66
77 ## Usage
88
9-Call `load_regex_files!` on the directory that contains regex files.
9+### Initialization
10+
11+- Call the `load_regex_files!` macro on the directory that contains regex files.
12+- Each file is loaded with the `m` and `x` flags
13+ - `m` (multiline): `^` and `$` match the start and end of lines, not just the entire input.
14+ - `x` (extended): allows whitespace and comments starting with `#` inside the regex.
1015
1116 ### Each regex file is a class with 4 main functions
1217
+6-0src/lib.rs
@@ -5,6 +5,12 @@ use std::fs;
55 use syn::{parse_macro_input, Ident, LitStr};
66
77 #[proc_macro]
8+/// Loads a folder filled with regular expression files ending with `.re`.
9+///
10+/// All regex files are loaded with the `m` and `x` flags.
11+///
12+/// - `m` (multi-line): `^` and `$` match the start and end of lines, not just the entire input.
13+/// - `x` (extended): allows whitespace and comments starting with `#` inside the regex.
814 pub fn load_regex_files(input: TokenStream) -> TokenStream {
915 let folder_path = parse_macro_input!(input as LitStr).value();
1016
+6-0tests/regex/Event.re
@@ -1,7 +1,13 @@
1+# This will create a struct called Event with the fields start, end, ampm, and activity
2+
3+# Get the start
14 (?<start>\d{1,2}:\d{1,2})
25 .
6+# Get the end time
37 (?<end>\d{1,2}:\d{1,2})
48 \s{0,2}
9+# Get the AM or PM after the times
510 (?<ampm>[AMPM]{2})
611 .
12+# Get the activity string
713 (?<activity>.+)