A rust macro that allows regular expression creation through independent files. Allows fully typed named groups.
improve docstrings
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 | ||
| 6 | 6 | |
| 7 | 7 | ## Usage |
| 8 | 8 | |
| 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. | |
| 10 | 15 | |
| 11 | 16 | ### Each regex file is a class with 4 main functions |
| 12 | 17 |
+6-0src/lib.rs
| @@ -5,6 +5,12 @@ use std::fs; | ||
| 5 | 5 | use syn::{parse_macro_input, Ident, LitStr}; |
| 6 | 6 | |
| 7 | 7 | #[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. | |
| 8 | 14 | pub fn load_regex_files(input: TokenStream) -> TokenStream { |
| 9 | 15 | let folder_path = parse_macro_input!(input as LitStr).value(); |
| 10 | 16 |
+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 | |
| 1 | 4 | (?<start>\d{1,2}:\d{1,2}) |
| 2 | 5 | . |
| 6 | +# Get the end time | |
| 3 | 7 | (?<end>\d{1,2}:\d{1,2}) |
| 4 | 8 | \s{0,2} |
| 9 | +# Get the AM or PM after the times | |
| 5 | 10 | (?<ampm>[AMPM]{2}) |
| 6 | 11 | . |
| 12 | +# Get the activity string | |
| 7 | 13 | (?<activity>.+) |