forked from gentoo-utils/gentoo-utils
impl Repo and md5-cache reading
This commit is contained in:
@@ -4,32 +4,59 @@ use mon::{Parser, alpha1, r#if, tag, whitespace1};
|
||||
|
||||
use crate::{
|
||||
Parseable,
|
||||
ebuild::{Conditional, Depend, Eapi, License, SrcUri},
|
||||
ebuild::{Conditional, Depend, Eapi, Eclass, License, SrcUri, Uri, UriPrefix},
|
||||
useflag::UseFlag,
|
||||
};
|
||||
|
||||
impl<'a> Parseable<'a, &'a str> for UriPrefix {
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
tag("+mirror")
|
||||
.map(|_| UriPrefix::Mirror)
|
||||
.or(tag("+fetch").map(|_| UriPrefix::Fetch))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Parseable<'a, &'a str> for Uri {
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
let protocol = alpha1::<&str>()
|
||||
.followed_by(tag("://"))
|
||||
.map(|output: &str| output.to_string());
|
||||
let path = r#if(|c: &char| !c.is_ascii_whitespace())
|
||||
.list(1..)
|
||||
.recognize()
|
||||
.map(|output: &str| output.to_string());
|
||||
|
||||
protocol
|
||||
.and(path)
|
||||
.map(|(protocol, path)| Uri { protocol, path })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Parseable<'a, &'a str> for SrcUri {
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
let protocol = alpha1::<&str>().followed_by(tag("://"));
|
||||
let filename = || {
|
||||
r#if(|c: &char| !c.is_ascii_whitespace())
|
||||
.list(1..)
|
||||
.recognize()
|
||||
.map(|output: &str| PathBuf::from(output))
|
||||
};
|
||||
let uri = UriPrefix::parser()
|
||||
.opt()
|
||||
.and(Uri::parser())
|
||||
.and(filename().preceded_by(tag(" -> ")).opt())
|
||||
.map(|((prefix, uri), filename)| SrcUri::Uri {
|
||||
prefix,
|
||||
uri,
|
||||
filename,
|
||||
});
|
||||
|
||||
let uri = r#if(|c: &char| !c.is_ascii_whitespace())
|
||||
.list(1..)
|
||||
.recognize()
|
||||
.map(|output: &str| output.to_string());
|
||||
|
||||
let name = r#if(|c: &char| !c.is_ascii_whitespace())
|
||||
.list(1..)
|
||||
.recognize()
|
||||
.map(|output: &str| PathBuf::from(output));
|
||||
|
||||
uri.preceded_by(protocol)
|
||||
.and(
|
||||
name.preceded_by(tag("->").delimited_by(whitespace1(), whitespace1()))
|
||||
.opt(),
|
||||
)
|
||||
.map(|(uri, file_name)| SrcUri { uri, file_name })
|
||||
uri.or(filename().map(|path: PathBuf| SrcUri::Filename(path)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +88,20 @@ impl<'a> Parseable<'a, &'a str> for Eapi {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Cant find information about eclass names in pms so we allow anything except
|
||||
// for whitespace.
|
||||
impl<'a> Parseable<'a, &'a str> for Eclass {
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
r#if(|c: &char| !c.is_ascii_whitespace())
|
||||
.list(1..)
|
||||
.recognize()
|
||||
.map(|output: &str| Eclass(output.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Parseable<'a, &'a str> for Depend<T>
|
||||
where
|
||||
T: Parseable<'a, &'a str>,
|
||||
|
||||
Reference in New Issue
Block a user