summaryrefslogtreecommitdiff
path: root/src/template.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-05-21 11:57:36 +1200
committerBen Bridle <ben@derelict.engineering>2025-05-21 11:57:36 +1200
commita749f3455678848e97208dd13fa2dcf64e4e28e5 (patch)
tree252975fb1d5d253b2f6ca9e85b0454b3134c2e42 /src/template.rs
downloadhighlight-a749f3455678848e97208dd13fa2dcf64e4e28e5.zip
Initial commit
Diffstat (limited to 'src/template.rs')
-rw-r--r--src/template.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/template.rs b/src/template.rs
new file mode 100644
index 0000000..67eaceb
--- /dev/null
+++ b/src/template.rs
@@ -0,0 +1,25 @@
+use fancy_regex::*;
+
+
+pub struct Template {
+ pub tag: String,
+ pub subtags: Vec<String>,
+ pub expression: Regex,
+}
+
+impl Template {
+ pub fn from_str(pattern: &str, tag: String) -> Self {
+ let pattern = format!("^(?:{pattern})");
+ let expression = Regex::new(&pattern).unwrap();
+
+ if let Some((head, tail)) = tag.split_once('(') {
+ if let Some(tail) = tail.strip_suffix(')') {
+ let tag = head.trim().to_string();
+ let subtags = tail.split(',').map(|t| t.trim().to_string()).collect();
+ return Self { tag, subtags, expression };
+ }
+ }
+ let subtags = Vec::new();
+ return Self { tag, subtags, expression };
+ }
+}