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 mon::{Parser, r#if, not, numeric1, one_of, opt, tag, take_while};
|
||||
use mon::{Parser, r#if, numeric1, one_of, tag};
|
||||
|
||||
use crate::{
|
||||
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> {
|
||||
numeric1()
|
||||
.followed_by(opt(tag("*")))
|
||||
.followed_by(tag("*").opt())
|
||||
.recognize()
|
||||
.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> {
|
||||
version_suffix_kind()
|
||||
.and(opt(version_number()))
|
||||
.and(version_number().opt())
|
||||
.map(|(kind, number)| VersionSuffix { kind, number })
|
||||
}
|
||||
|
||||
pub fn version<'a>() -> impl Parser<&'a str, Output = Version> {
|
||||
let numbers = version_number().separated_list1(tag("."));
|
||||
let suffixes = version_suffix().separated_list(tag("_"));
|
||||
let numbers = version_number().separated_list(tag("."), 1..);
|
||||
let suffixes = version_suffix().separated_list(tag("_"), 0..);
|
||||
let rev = version_number().preceded_by(tag("-r"));
|
||||
|
||||
numbers
|
||||
.and(opt(r#if(|c: &char| {
|
||||
c.is_ascii_alphabetic() && c.is_ascii_lowercase()
|
||||
})))
|
||||
.and(opt(suffixes.preceded_by(tag("_"))))
|
||||
.and(opt(rev))
|
||||
.and(r#if(|c: &char| c.is_ascii_alphabetic() && c.is_ascii_lowercase()).opt())
|
||||
.and(suffixes.preceded_by(tag("_")).opt())
|
||||
.and(rev.opt())
|
||||
.map(|(((numbers, letter), suffixes), rev)| Version {
|
||||
numbers,
|
||||
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> {
|
||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||
let rest = take_while(r#if(|c: &char| {
|
||||
c.is_ascii_alphanumeric() || "+_.-".contains(*c)
|
||||
}));
|
||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).list(0..);
|
||||
|
||||
start
|
||||
.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> {
|
||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||
let rest = take_while(
|
||||
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+".contains(*c)).or(one_of("-".chars())
|
||||
.and_not(
|
||||
version()
|
||||
.preceded_by(tag("-"))
|
||||
.followed_by(not(r#if(|c: &char| {
|
||||
c.is_ascii_alphanumeric() || "_+-".contains(*c)
|
||||
}))),
|
||||
)),
|
||||
);
|
||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "_+".contains(*c))
|
||||
.or(one_of("-".chars()).and_not(
|
||||
version().preceded_by(tag("-")).followed_by(
|
||||
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+-".contains(*c)).not(),
|
||||
),
|
||||
))
|
||||
.list(0..);
|
||||
|
||||
start
|
||||
.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> {
|
||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||
let rest = take_while(r#if(|c: &char| {
|
||||
c.is_ascii_alphanumeric() || "+_.-".contains(*c)
|
||||
}));
|
||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).list(0..);
|
||||
|
||||
start
|
||||
.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> {
|
||||
opt(slotname())
|
||||
.and(opt(slotname().preceded_by(tag("/"))))
|
||||
.and(opt(slot_operator()))
|
||||
slotname()
|
||||
.opt()
|
||||
.and(slotname().preceded_by(tag("/")).opt())
|
||||
.and(slot_operator().opt())
|
||||
.map(|((slot, sub), operator)| Slot {
|
||||
slot,
|
||||
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> {
|
||||
let a = useflag()
|
||||
.and(opt(usedep_sign()))
|
||||
.and(usedep_sign().opt())
|
||||
.preceded_by(tag("-"))
|
||||
.map(|(flag, sign)| UseDep {
|
||||
negate: Some(UseDepNegate::Minus),
|
||||
@@ -146,7 +138,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||
});
|
||||
|
||||
let b = useflag()
|
||||
.and(opt(usedep_sign()))
|
||||
.and(usedep_sign().opt())
|
||||
.preceded_by(tag("!"))
|
||||
.followed_by(tag("?"))
|
||||
.map(|(flag, sign)| UseDep {
|
||||
@@ -157,7 +149,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||
});
|
||||
|
||||
let c = useflag()
|
||||
.and(opt(usedep_sign()))
|
||||
.and(usedep_sign().opt())
|
||||
.followed_by(tag("?"))
|
||||
.map(|(flag, sign)| UseDep {
|
||||
negate: None,
|
||||
@@ -167,7 +159,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||
});
|
||||
|
||||
let d = useflag()
|
||||
.and(opt(usedep_sign()))
|
||||
.and(usedep_sign().opt())
|
||||
.preceded_by(tag("!"))
|
||||
.followed_by(tag("="))
|
||||
.map(|(flag, sign)| UseDep {
|
||||
@@ -178,7 +170,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||
});
|
||||
|
||||
let e = useflag()
|
||||
.and(opt(usedep_sign()))
|
||||
.and(usedep_sign().opt())
|
||||
.followed_by(tag("="))
|
||||
.map(|(flag, sign)| UseDep {
|
||||
negate: None,
|
||||
@@ -188,7 +180,7 @@ pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||
});
|
||||
|
||||
let f = useflag()
|
||||
.and(opt(usedep_sign()))
|
||||
.and(usedep_sign().opt())
|
||||
.map(|(flag, sign)| UseDep {
|
||||
negate: None,
|
||||
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> {
|
||||
opt(blocker())
|
||||
.and(opt(version_operator()))
|
||||
blocker()
|
||||
.opt()
|
||||
.and(version_operator().opt())
|
||||
.and(category())
|
||||
.and(name().preceded_by(tag("/")))
|
||||
.and(opt(version().preceded_by(tag("-"))))
|
||||
.and(opt(slot().preceded_by(tag(":"))))
|
||||
.and(opt(usedep()
|
||||
.separated_list(tag(","))
|
||||
.delimited_by(tag("["), tag("]"))))
|
||||
.and(version().preceded_by(tag("-")).opt())
|
||||
.and(slot().preceded_by(tag(":")).opt())
|
||||
.and(
|
||||
usedep()
|
||||
.separated_list(tag(","), 0..)
|
||||
.delimited_by(tag("["), tag("]"))
|
||||
.opt(),
|
||||
)
|
||||
.map(
|
||||
|((((((blocker, version_operator), category), name), version), slot), usedeps)| Atom {
|
||||
blocker,
|
||||
|
||||
Reference in New Issue
Block a user