Commit 4200e108 authored by Scott Abbey's avatar Scott Abbey

Begin range parsing with regex to match strings

parent 9846f184
......@@ -4,6 +4,7 @@ extern crate regex;
extern crate lazy_static;
pub mod version;
pub mod range;
// for private stuff the two share
mod common;
use regex::Regex;
lazy_static! {
static ref REGEX: Regex = {
// an operation can be:
//
// * =
// * >
// * >=
// * <
// * <=
// * ~
// * ^
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 major = numeric_identifier;
// minor can be either a number or a wildcard. *, x, and X are wildcards.
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 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
(?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
$",
operation,
major,
minor,
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