Created
January 30, 2025 03:00
-
-
Save Absolucy/b04c8c5bcafae5d2abf6919833454110 to your computer and use it in GitHub Desktop.
i love regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static THRESHOLD_SPLIT_REGEX: Lazy<Regex> = Lazy::new(|| { | |
Regex::new(r"(?im)(<br>|([^:]<b>))[^$]").expect("failed to setup THRESHOLD_SPLIT_REGEX") | |
}); | |
static THRESHOLD_PARSE_REGEX: Lazy<Regex> = Lazy::new(|| { | |
Regex::new(r"(?im)(?:<b>)?(?P<name>[[[:alpha:]] ]+) ?(?P<level>[[:digit:]]{1,2})?[[:space:]]?(?:</b>[[:space:]]*|:</b>[[:space:]]*)(?P<desc>[^<>\n]+)").expect("failed to setup THRESHOLD_PARSE_REGEX") | |
}); | |
static SEVERITYSET_PROC_PARSE_REGEX: Lazy<FancyRegex> = Lazy::new(|| { | |
FancyRegex::new( | |
r"(?mxi) # setup flags | |
(?P<severityset> | |
# find the severityset proc header | |
(?P<path>\/datum\/symptom\/[[:graph:]]+)\/severityset\( | |
# handle prefix of `var/` or just `/` before the argument | |
(?:var)?\/? | |
# advance disease argument | |
datum\/disease\/advance\/A | |
\) | |
# match inner code | |
(?:.|\s)*?) | |
# stop before we touch another definition | |
[\r\n\t]+(?:\/|$) | |
", | |
) | |
.expect("failed to setup SEVERITYSET_PROC_PARSE_REGEX") | |
}); | |
static SEVERITY_BLOCK_PARSE_REGEX: Lazy<FancyRegex> = Lazy::new(|| { | |
FancyRegex::new( | |
r" | |
(?mxi) # setup flags | |
# get indent level at beginning of block | |
(?P<indent>[[:blank:]]+) | |
# parse if statement | |
if[ \t]*\(A\.(?P<var>[[:alpha:]]+)[ \t]*(?P<op>>=|>|<|<=)[ | |
\t]*(?P<val>[[:digit:]]+)[ \t]*\) # handle any potential comments | |
[ [:print:] ]*\n | |
# alright, now we check the next line to ensure it has the same indent | |
(?:(?P=indent){2,}.*\n*)+(?!(?P=indent))", | |
) | |
.expect("failed to setup SEVERITY_BLOCK_PARSE_REGEX") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment