Commit ffa9227a authored by Scott Abbey's avatar Scott Abbey

Add support for multiple range predicates

parent 6f159844
......@@ -33,13 +33,13 @@ lazy_static! {
// parse_version() will parse this further.
let pre = letters_numbers_dash_dot;
let regex = format!(r"^(?x) # heck yes x mode
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,
......@@ -119,6 +119,28 @@ pub fn parse(range: &str) -> Result<VersionReq, String> {
});
}
let range = range.trim();
let predicates: Result<Vec<_>, String> = REGEX.find_iter(range)
.map(|pos| {
let range = &range[pos.0..pos.1];
parse_predicate(range)
}).collect();
let predicates = try!(predicates);
if predicates.len() == 0 {
return Err(String::from("VersionReq did not parse properly"));
}
Ok(VersionReq {
predicates: predicates,
})
}
pub fn parse_predicate(range: &str) -> Result<Predicate, String> {
let captures = match REGEX.captures(range.trim()) {
Some(captures) => captures,
None => return Err(From::from("VersionReq did not parse properly.")),
......@@ -176,16 +198,12 @@ pub fn parse(range: &str) -> Result<VersionReq, String> {
let pre = captures.name("pre").map(common::parse_meta).unwrap_or_else(Vec::new);
let predicate = Predicate {
Ok(Predicate {
op: operation,
major: major,
minor: minor,
patch: patch,
pre: pre,
};
Ok(VersionReq {
predicates: vec![predicate],
})
}
......
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