forked from gentoo-utils/gentoo-utils
port to new mon parsers
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use core::option::Option::None;
|
use core::option::Option::None;
|
||||||
|
|
||||||
use mon::{Parser, r#if, not, numeric1, one_of, opt, tag, take_while};
|
use mon::{Parser, r#if, numeric1, one_of, tag};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
atom::{
|
atom::{
|
||||||
@@ -29,7 +29,7 @@ pub fn version_operator<'a>() -> impl Parser<&'a str, Output = VersionOperator>
|
|||||||
|
|
||||||
pub fn version_number<'a>() -> impl Parser<&'a str, Output = VersionNumber> {
|
pub fn version_number<'a>() -> impl Parser<&'a str, Output = VersionNumber> {
|
||||||
numeric1()
|
numeric1()
|
||||||
.followed_by(opt(tag("*")))
|
.followed_by(tag("*").opt())
|
||||||
.recognize()
|
.recognize()
|
||||||
.map(|output: &str| VersionNumber(output.to_string()))
|
.map(|output: &str| VersionNumber(output.to_string()))
|
||||||
}
|
}
|
||||||
@@ -45,21 +45,19 @@ pub fn version_suffix_kind<'a>() -> impl Parser<&'a str, Output = VersionSuffixK
|
|||||||
|
|
||||||
pub fn version_suffix<'a>() -> impl Parser<&'a str, Output = VersionSuffix> {
|
pub fn version_suffix<'a>() -> impl Parser<&'a str, Output = VersionSuffix> {
|
||||||
version_suffix_kind()
|
version_suffix_kind()
|
||||||
.and(opt(version_number()))
|
.and(version_number().opt())
|
||||||
.map(|(kind, number)| VersionSuffix { kind, number })
|
.map(|(kind, number)| VersionSuffix { kind, number })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn version<'a>() -> impl Parser<&'a str, Output = Version> {
|
pub fn version<'a>() -> impl Parser<&'a str, Output = Version> {
|
||||||
let numbers = version_number().separated_list1(tag("."));
|
let numbers = version_number().separated_list(tag("."), 1..);
|
||||||
let suffixes = version_suffix().separated_list(tag("_"));
|
let suffixes = version_suffix().separated_list(tag("_"), 0..);
|
||||||
let rev = version_number().preceded_by(tag("-r"));
|
let rev = version_number().preceded_by(tag("-r"));
|
||||||
|
|
||||||
numbers
|
numbers
|
||||||
.and(opt(r#if(|c: &char| {
|
.and(r#if(|c: &char| c.is_ascii_alphabetic() && c.is_ascii_lowercase()).opt())
|
||||||
c.is_ascii_alphabetic() && c.is_ascii_lowercase()
|
.and(suffixes.preceded_by(tag("_")).opt())
|
||||||
})))
|
.and(rev.opt())
|
||||||
.and(opt(suffixes.preceded_by(tag("_"))))
|
|
||||||
.and(opt(rev))
|
|
||||||
.map(|(((numbers, letter), suffixes), rev)| Version {
|
.map(|(((numbers, letter), suffixes), rev)| Version {
|
||||||
numbers,
|
numbers,
|
||||||
letter,
|
letter,
|
||||||
@@ -70,9 +68,7 @@ pub fn version<'a>() -> impl Parser<&'a str, Output = Version> {
|
|||||||
|
|
||||||
pub fn category<'a>() -> impl Parser<&'a str, Output = Category> {
|
pub fn category<'a>() -> impl Parser<&'a str, Output = Category> {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||||
let rest = take_while(r#if(|c: &char| {
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).list(0..);
|
||||||
c.is_ascii_alphanumeric() || "+_.-".contains(*c)
|
|
||||||
}));
|
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -82,16 +78,13 @@ pub fn category<'a>() -> impl Parser<&'a str, Output = Category> {
|
|||||||
|
|
||||||
pub fn name<'a>() -> impl Parser<&'a str, Output = Name> {
|
pub fn name<'a>() -> impl Parser<&'a str, Output = Name> {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||||
let rest = take_while(
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "_+".contains(*c))
|
||||||
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+".contains(*c)).or(one_of("-".chars())
|
.or(one_of("-".chars()).and_not(
|
||||||
.and_not(
|
version().preceded_by(tag("-")).followed_by(
|
||||||
version()
|
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+-".contains(*c)).not(),
|
||||||
.preceded_by(tag("-"))
|
),
|
||||||
.followed_by(not(r#if(|c: &char| {
|
))
|
||||||
c.is_ascii_alphanumeric() || "_+-".contains(*c)
|
.list(0..);
|
||||||
}))),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -107,9 +100,7 @@ pub fn slot_operator<'a>() -> impl Parser<&'a str, Output = SlotOperator> {
|
|||||||
|
|
||||||
pub fn slotname<'a>() -> impl Parser<&'a str, Output = SlotName> {
|
pub fn slotname<'a>() -> impl Parser<&'a str, Output = SlotName> {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||||
let rest = take_while(r#if(|c: &char| {
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).list(0..);
|
||||||
c.is_ascii_alphanumeric() || "+_.-".contains(*c)
|
|
||||||
}));
|
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -118,9 +109,10 @@ pub fn slotname<'a>() -> impl Parser<&'a str, Output = SlotName> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn slot<'a>() -> impl Parser<&'a str, Output = Slot> {
|
pub fn slot<'a>() -> impl Parser<&'a str, Output = Slot> {
|
||||||
opt(slotname())
|
slotname()
|
||||||
.and(opt(slotname().preceded_by(tag("/"))))
|
.opt()
|
||||||
.and(opt(slot_operator()))
|
.and(slotname().preceded_by(tag("/")).opt())
|
||||||
|
.and(slot_operator().opt())
|
||||||
.map(|((slot, sub), operator)| Slot {
|
.map(|((slot, sub), operator)| Slot {
|
||||||
slot,
|
slot,
|
||||||
sub,
|
sub,
|
||||||
@@ -136,7 +128,7 @@ pub fn usedep_sign<'a>() -> impl Parser<&'a str, Output = UseDepSign> {
|
|||||||
|
|
||||||
pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||||
let a = useflag()
|
let a = useflag()
|
||||||
.and(opt(usedep_sign()))
|
.and(usedep_sign().opt())
|
||||||
.preceded_by(tag("-"))
|
.preceded_by(tag("-"))
|
||||||
.map(|(flag, sign)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
negate: Some(UseDepNegate::Minus),
|
negate: Some(UseDepNegate::Minus),
|
||||||
@@ -146,7 +138,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let b = useflag()
|
let b = useflag()
|
||||||
.and(opt(usedep_sign()))
|
.and(usedep_sign().opt())
|
||||||
.preceded_by(tag("!"))
|
.preceded_by(tag("!"))
|
||||||
.followed_by(tag("?"))
|
.followed_by(tag("?"))
|
||||||
.map(|(flag, sign)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
@@ -157,7 +149,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let c = useflag()
|
let c = useflag()
|
||||||
.and(opt(usedep_sign()))
|
.and(usedep_sign().opt())
|
||||||
.followed_by(tag("?"))
|
.followed_by(tag("?"))
|
||||||
.map(|(flag, sign)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
negate: None,
|
negate: None,
|
||||||
@@ -167,7 +159,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let d = useflag()
|
let d = useflag()
|
||||||
.and(opt(usedep_sign()))
|
.and(usedep_sign().opt())
|
||||||
.preceded_by(tag("!"))
|
.preceded_by(tag("!"))
|
||||||
.followed_by(tag("="))
|
.followed_by(tag("="))
|
||||||
.map(|(flag, sign)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
@@ -178,7 +170,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let e = useflag()
|
let e = useflag()
|
||||||
.and(opt(usedep_sign()))
|
.and(usedep_sign().opt())
|
||||||
.followed_by(tag("="))
|
.followed_by(tag("="))
|
||||||
.map(|(flag, sign)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
negate: None,
|
negate: None,
|
||||||
@@ -188,7 +180,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let f = useflag()
|
let f = useflag()
|
||||||
.and(opt(usedep_sign()))
|
.and(usedep_sign().opt())
|
||||||
.map(|(flag, sign)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
negate: None,
|
negate: None,
|
||||||
flag,
|
flag,
|
||||||
@@ -200,15 +192,19 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> {
|
pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> {
|
||||||
opt(blocker())
|
blocker()
|
||||||
.and(opt(version_operator()))
|
.opt()
|
||||||
|
.and(version_operator().opt())
|
||||||
.and(category())
|
.and(category())
|
||||||
.and(name().preceded_by(tag("/")))
|
.and(name().preceded_by(tag("/")))
|
||||||
.and(opt(version().preceded_by(tag("-"))))
|
.and(version().preceded_by(tag("-")).opt())
|
||||||
.and(opt(slot().preceded_by(tag(":"))))
|
.and(slot().preceded_by(tag(":")).opt())
|
||||||
.and(opt(usedep()
|
.and(
|
||||||
.separated_list(tag(","))
|
usedep()
|
||||||
.delimited_by(tag("["), tag("]"))))
|
.separated_list(tag(","), 0..)
|
||||||
|
.delimited_by(tag("["), tag("]"))
|
||||||
|
.opt(),
|
||||||
|
)
|
||||||
.map(
|
.map(
|
||||||
|((((((blocker, version_operator), category), name), version), slot), usedeps)| Atom {
|
|((((((blocker, version_operator), category), name), version), slot), usedeps)| Atom {
|
||||||
blocker,
|
blocker,
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ use crate::{
|
|||||||
|
|
||||||
fn expr(it: InputIter<&str>) -> ParserResult<&str, Expr> {
|
fn expr(it: InputIter<&str>) -> ParserResult<&str, Expr> {
|
||||||
let all_of = expr
|
let all_of = expr
|
||||||
.separated_list1(whitespace1())
|
.separated_list(whitespace1(), 1..)
|
||||||
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
||||||
.map(|exprs| Expr::AllOf(exprs));
|
.map(|exprs| Expr::AllOf(exprs));
|
||||||
|
|
||||||
let any_of = expr
|
let any_of = expr
|
||||||
.separated_list1(whitespace1())
|
.separated_list(whitespace1(), 1..)
|
||||||
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
||||||
.preceded_by(tag("||").followed_by(whitespace1()))
|
.preceded_by(tag("||").followed_by(whitespace1()))
|
||||||
.map(|exprs| Expr::AnyOf(exprs));
|
.map(|exprs| Expr::AnyOf(exprs));
|
||||||
|
|
||||||
let one_of = expr
|
let one_of = expr
|
||||||
.separated_list1(whitespace1())
|
.separated_list(whitespace1(), 1..)
|
||||||
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
||||||
.preceded_by(tag("^^").followed_by(whitespace1()))
|
.preceded_by(tag("^^").followed_by(whitespace1()))
|
||||||
.map(|exprs| Expr::OneOf(exprs));
|
.map(|exprs| Expr::OneOf(exprs));
|
||||||
@@ -44,7 +44,7 @@ fn conditional<'a>() -> impl Parser<&'a str, Output = Conditional> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn exprs<'a>() -> impl Parser<&'a str, Output = Vec<Expr>> {
|
pub fn exprs<'a>() -> impl Parser<&'a str, Output = Vec<Expr>> {
|
||||||
expr.separated_list1(whitespace1())
|
expr.separated_list(whitespace1(), 0..)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
use mon::{Parser, r#if, take_while};
|
use mon::{Parser, r#if};
|
||||||
|
|
||||||
use crate::useflag::UseFlag;
|
use crate::useflag::UseFlag;
|
||||||
|
|
||||||
pub fn useflag<'a>() -> impl Parser<&'a str, Output = UseFlag> {
|
pub fn useflag<'a>() -> impl Parser<&'a str, Output = UseFlag> {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric());
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric());
|
||||||
let rest = take_while(r#if(|c: &char| {
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_@-".contains(*c)).list(0..);
|
||||||
c.is_ascii_alphanumeric() || "+_@-".contains(*c)
|
|
||||||
}));
|
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ fn parse_md5_cache() {
|
|||||||
|
|
||||||
for line in metadata.lines() {
|
for line in metadata.lines() {
|
||||||
if line.starts_with("DEPEND=") {
|
if line.starts_with("DEPEND=") {
|
||||||
|
eprintln!("{line}");
|
||||||
|
eprintln!();
|
||||||
depend::parsers::exprs()
|
depend::parsers::exprs()
|
||||||
.ignore()
|
.ignore()
|
||||||
.or(eof())
|
.or(eof())
|
||||||
|
|||||||
Reference in New Issue
Block a user