Commit c8bc8b52 authored by Scott Abbey's avatar Scott Abbey

Fix some regexes

parent c16f3b87
......@@ -14,31 +14,33 @@ lazy_static! {
// * <=
// * ~
// * ^
let operation = r"=|>|(:?>=)|<|(:?<=)|~|\^";
let operation = r"=|>|>=|<|<=|~|\^";
// a numeric identifier is either zero or multiple numbers without a leading zero
let numeric_identifier = r"0|(:?[1-9][0-9]*)";
let numeric_identifier = r"0|[1-9][0-9]*";
let major = numeric_identifier;
// minor can be either a number or a wildcard. *, x, and X are wildcards.
let minor = format!(r"(:?{})|\*|[xX]", numeric_identifier);
let minor = format!(r"{}|\*|[xX]", numeric_identifier);
// patch can be either a number or a wildcard. *, x, and X are wildcards.
let patch = format!(r"(:?{})|\*|[xX]", numeric_identifier);
let patch = format!(r"{}|\*|[xX]", numeric_identifier);
let letters_numbers_dash_dot = r"[-.A-Za-z0-9]+";
// This regex does not fully parse prereleases, just extracts the whole prerelease string.
// parse_version() will parse this further.
let pre = letters_numbers_dash_dot;
let regex = format!(r"(?x) # heck yes x mode
^\s* # leading whitespace
(?P<operation>{})?\s* # optional operation
(?P<major>{}) # major version
(:?\.(?P<minor>{}))? # optional dot and then minor
(:?\.(?P<patch>{}))? # optional dot and then patch
(:?-(?P<pre>{}))? # optional prerelease version
(?:\.(?P<minor>{}))? # optional dot and then minor
(?:\.(?P<patch>{}))? # optional dot and then patch
(?:-(?P<pre>{}))? # optional prerelease version
\s*$ # trailing whitespace
",
operation,
major,
......@@ -46,7 +48,7 @@ lazy_static! {
patch,
pre);
let regex = Regex::new(&regex);
// this unwrap is okay because everything above here is const, so this will never fail.
regex.unwrap()
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment