forked from gentoo-utils/gentoo-utils
update parsers to use the ParserIter trait from mon
This commit is contained in:
@@ -4,7 +4,7 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mon = { git = "https://jturnerusa.dev/cgit/mon/", rev = "821f132bd5c8678327c2ab8764bd7d172a7b7ee4" }
|
mon = { git = "https://jturnerusa.dev/cgit/mon/", rev = "da2980e5c9e7da3839eb71e450f206b1121d326e" }
|
||||||
get = { git = "https://jturnerusa.dev/cgit/get/", rev = "cd5f75b65777a855ab010c3137304ac05f2e56b8" }
|
get = { git = "https://jturnerusa.dev/cgit/get/", rev = "cd5f75b65777a855ab010c3137304ac05f2e56b8" }
|
||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
thiserror = "2.0.17"
|
thiserror = "2.0.17"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use core::option::Option::None;
|
use core::option::Option::None;
|
||||||
|
|
||||||
use mon::{Parser, r#if, numeric1, one_of, tag};
|
use mon::{Parser, ParserIter, r#if, numeric1, one_of, tag};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Parseable,
|
Parseable,
|
||||||
@@ -74,8 +74,8 @@ impl<'a> Parseable<'a, &'a str> for Version {
|
|||||||
type Parser = impl Parser<&'a str, Output = Self>;
|
type Parser = impl Parser<&'a str, Output = Self>;
|
||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let numbers = VersionNumber::parser().separated_by(tag("."), 1..);
|
let numbers = VersionNumber::parser().separated_by(tag(".")).at_least(1);
|
||||||
let suffixes = VersionSuffix::parser().separated_by(tag("_"), 0..);
|
let suffixes = VersionSuffix::parser().separated_by(tag("_")).many();
|
||||||
let rev = VersionNumber::parser().preceded_by(tag("-r"));
|
let rev = VersionNumber::parser().preceded_by(tag("-r"));
|
||||||
|
|
||||||
numbers
|
numbers
|
||||||
@@ -96,7 +96,9 @@ impl<'a> Parseable<'a, &'a str> for Category {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).repeated(0..);
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c))
|
||||||
|
.repeated()
|
||||||
|
.many();
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -116,7 +118,8 @@ impl<'a> Parseable<'a, &'a str> for Name {
|
|||||||
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+-".contains(*c)).not(),
|
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+-".contains(*c)).not(),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.repeated(0..);
|
.repeated()
|
||||||
|
.many();
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -140,7 +143,9 @@ impl<'a> Parseable<'a, &'a str> for SlotName {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_');
|
||||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).repeated(0..);
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c))
|
||||||
|
.repeated()
|
||||||
|
.many();
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -257,7 +262,8 @@ impl<'a> Parseable<'a, &'a str> for Atom {
|
|||||||
.and(Slot::parser().preceded_by(tag(":")).opt())
|
.and(Slot::parser().preceded_by(tag(":")).opt())
|
||||||
.and(
|
.and(
|
||||||
UseDep::parser()
|
UseDep::parser()
|
||||||
.separated_by(tag(","), 0..)
|
.separated_by(tag(","))
|
||||||
|
.many()
|
||||||
.delimited_by(tag("["), tag("]"))
|
.delimited_by(tag("["), tag("]"))
|
||||||
.opt(),
|
.opt(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use mon::{Parser, alpha1, r#if, tag, whitespace1};
|
use mon::{Parser, ParserIter, alpha1, r#if, tag, whitespace1};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Parseable,
|
Parseable,
|
||||||
@@ -26,7 +26,8 @@ impl<'a> Parseable<'a, &'a str> for Uri {
|
|||||||
.followed_by(tag("://"))
|
.followed_by(tag("://"))
|
||||||
.map(|output: &str| output.to_string());
|
.map(|output: &str| output.to_string());
|
||||||
let path = r#if(|c: &char| !c.is_ascii_whitespace())
|
let path = r#if(|c: &char| !c.is_ascii_whitespace())
|
||||||
.repeated(1..)
|
.repeated()
|
||||||
|
.at_least(1)
|
||||||
.recognize()
|
.recognize()
|
||||||
.map(|output: &str| output.to_string());
|
.map(|output: &str| output.to_string());
|
||||||
|
|
||||||
@@ -42,7 +43,8 @@ impl<'a> Parseable<'a, &'a str> for SrcUri {
|
|||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let filename = || {
|
let filename = || {
|
||||||
r#if(|c: &char| !c.is_ascii_whitespace())
|
r#if(|c: &char| !c.is_ascii_whitespace())
|
||||||
.repeated(1..)
|
.repeated()
|
||||||
|
.at_least(1)
|
||||||
.recognize()
|
.recognize()
|
||||||
.map(|output: &str| PathBuf::from(output))
|
.map(|output: &str| PathBuf::from(output))
|
||||||
};
|
};
|
||||||
@@ -65,7 +67,9 @@ impl<'a> Parseable<'a, &'a str> for License {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || "_".contains(*c));
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || "_".contains(*c));
|
||||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).repeated(0..);
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c))
|
||||||
|
.repeated()
|
||||||
|
.many();
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -79,7 +83,9 @@ impl<'a> Parseable<'a, &'a str> for Eapi {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || "_".contains(*c));
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric() || "_".contains(*c));
|
||||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)).repeated(0..);
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c))
|
||||||
|
.repeated()
|
||||||
|
.many();
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
@@ -96,7 +102,8 @@ impl<'a> Parseable<'a, &'a str> for Eclass {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
r#if(|c: &char| !c.is_ascii_whitespace())
|
r#if(|c: &char| !c.is_ascii_whitespace())
|
||||||
.repeated(1..)
|
.repeated()
|
||||||
|
.at_least(1)
|
||||||
.recognize()
|
.recognize()
|
||||||
.map(|output: &str| Eclass(output.to_string()))
|
.map(|output: &str| Eclass(output.to_string()))
|
||||||
}
|
}
|
||||||
@@ -111,18 +118,21 @@ where
|
|||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
|it| {
|
|it| {
|
||||||
let all_of_group = Depend::parser()
|
let all_of_group = Depend::parser()
|
||||||
.separated_by(whitespace1(), 1..)
|
.separated_by(whitespace1())
|
||||||
|
.at_least(1)
|
||||||
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
.delimited_by(tag("(").followed_by(whitespace1()), tag(")"))
|
||||||
.map(|exprs| Depend::AllOf(exprs));
|
.map(|exprs| Depend::AllOf(exprs));
|
||||||
|
|
||||||
let any_of_group = Depend::parser()
|
let any_of_group = Depend::parser()
|
||||||
.separated_by(whitespace1(), 1..)
|
.separated_by(whitespace1())
|
||||||
|
.at_least(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| Depend::AnyOf(exprs));
|
.map(|exprs| Depend::AnyOf(exprs));
|
||||||
|
|
||||||
let one_of_group = Depend::parser()
|
let one_of_group = Depend::parser()
|
||||||
.separated_by(whitespace1(), 1..)
|
.separated_by(whitespace1())
|
||||||
|
.at_least(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| Depend::OneOf(exprs));
|
.map(|exprs| Depend::OneOf(exprs));
|
||||||
@@ -131,7 +141,8 @@ where
|
|||||||
.followed_by(whitespace1())
|
.followed_by(whitespace1())
|
||||||
.and(
|
.and(
|
||||||
Depend::parser()
|
Depend::parser()
|
||||||
.separated_by(whitespace1(), 1..)
|
.separated_by(whitespace1())
|
||||||
|
.at_least(1)
|
||||||
.delimited_by(tag("(").followed_by(whitespace1()), tag(")")),
|
.delimited_by(tag("(").followed_by(whitespace1()), tag(")")),
|
||||||
)
|
)
|
||||||
.map(|(conditional, exprs)| Depend::ConditionalGroup(conditional, exprs));
|
.map(|(conditional, exprs)| Depend::ConditionalGroup(conditional, exprs));
|
||||||
@@ -164,7 +175,7 @@ impl<'a> Parseable<'a, &'a str> for Conditional {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
use mon::input::InputIter;
|
use mon::{ParserIter, input::InputIter};
|
||||||
|
|
||||||
use crate::{atom::Atom, ebuild::Depend};
|
use crate::{atom::Atom, ebuild::Depend};
|
||||||
|
|
||||||
@@ -189,7 +200,8 @@ mod test {
|
|||||||
let it = InputIter::new("flag? ( || ( foo/bar foo/bar ) )");
|
let it = InputIter::new("flag? ( || ( foo/bar foo/bar ) )");
|
||||||
|
|
||||||
Depend::<Atom>::parser()
|
Depend::<Atom>::parser()
|
||||||
.separated_by(whitespace1(), 0..)
|
.separated_by(whitespace1())
|
||||||
|
.many()
|
||||||
.check_finished(it)
|
.check_finished(it)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use get::Get;
|
use get::Get;
|
||||||
|
|
||||||
use mon::{Parser, input::InputIter, tag, whitespace1};
|
use mon::{Parser, ParserIter, input::InputIter, tag, whitespace1};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Parseable,
|
Parseable,
|
||||||
@@ -200,7 +200,8 @@ fn read_src_uri(input: &str) -> Option<Result<Vec<Depend<SrcUri>>, Error>> {
|
|||||||
.find_map(|line| line.strip_prefix("SRC_URI="))?;
|
.find_map(|line| line.strip_prefix("SRC_URI="))?;
|
||||||
|
|
||||||
match Depend::<SrcUri>::parser()
|
match Depend::<SrcUri>::parser()
|
||||||
.separated_by(whitespace1(), 0..)
|
.separated_by(whitespace1())
|
||||||
|
.many()
|
||||||
.parse_finished(InputIter::new(line))
|
.parse_finished(InputIter::new(line))
|
||||||
{
|
{
|
||||||
Ok(slot) => Some(Ok(slot)),
|
Ok(slot) => Some(Ok(slot)),
|
||||||
@@ -223,7 +224,8 @@ fn read_inherit(input: &str) -> Option<Result<Vec<Eclass>, Error>> {
|
|||||||
.find_map(|line| line.strip_prefix("INHERIT="))?;
|
.find_map(|line| line.strip_prefix("INHERIT="))?;
|
||||||
|
|
||||||
match Eclass::parser()
|
match Eclass::parser()
|
||||||
.separated_by(whitespace1(), 0..)
|
.separated_by(whitespace1())
|
||||||
|
.many()
|
||||||
.parse_finished(InputIter::new(line))
|
.parse_finished(InputIter::new(line))
|
||||||
{
|
{
|
||||||
Ok(inherit) => Some(Ok(inherit)),
|
Ok(inherit) => Some(Ok(inherit)),
|
||||||
@@ -235,7 +237,8 @@ fn read_iuse(input: &str) -> Option<Result<Vec<IUseFlag>, Error>> {
|
|||||||
let line = input.lines().find_map(|line| line.strip_prefix("IUSE="))?;
|
let line = input.lines().find_map(|line| line.strip_prefix("IUSE="))?;
|
||||||
|
|
||||||
match IUseFlag::parser()
|
match IUseFlag::parser()
|
||||||
.separated_by(whitespace1(), 0..)
|
.separated_by(whitespace1())
|
||||||
|
.many()
|
||||||
.parse_finished(InputIter::new(line))
|
.parse_finished(InputIter::new(line))
|
||||||
{
|
{
|
||||||
Ok(iuse) => Some(Ok(iuse)),
|
Ok(iuse) => Some(Ok(iuse)),
|
||||||
@@ -249,7 +252,8 @@ fn read_license(input: &str) -> Option<Result<Vec<Depend<License>>, Error>> {
|
|||||||
.find_map(|line| line.strip_suffix("LICENSE="))?;
|
.find_map(|line| line.strip_suffix("LICENSE="))?;
|
||||||
|
|
||||||
match Depend::<License>::parser()
|
match Depend::<License>::parser()
|
||||||
.separated_by(whitespace1(), 0..)
|
.separated_by(whitespace1())
|
||||||
|
.many()
|
||||||
.parse_finished(InputIter::new(line))
|
.parse_finished(InputIter::new(line))
|
||||||
{
|
{
|
||||||
Ok(license) => Some(Ok(license)),
|
Ok(license) => Some(Ok(license)),
|
||||||
@@ -297,7 +301,8 @@ fn read_idepend(input: &str) -> Option<Result<Vec<Depend<Atom>>, Error>> {
|
|||||||
|
|
||||||
fn parse_depends(line: &str) -> Result<Vec<Depend<Atom>>, Error> {
|
fn parse_depends(line: &str) -> Result<Vec<Depend<Atom>>, Error> {
|
||||||
Depend::<Atom>::parser()
|
Depend::<Atom>::parser()
|
||||||
.separated_by(whitespace1(), 0..)
|
.separated_by(whitespace1())
|
||||||
|
.many()
|
||||||
.parse_finished(InputIter::new(line))
|
.parse_finished(InputIter::new(line))
|
||||||
.map_err(|_| Error::Parser(line.to_string()))
|
.map_err(|_| Error::Parser(line.to_string()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use mon::{Parser, r#if, tag};
|
use mon::{Parser, ParserIter, r#if, tag};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Parseable,
|
Parseable,
|
||||||
@@ -10,7 +10,9 @@ impl<'a> Parseable<'a, &'a str> for UseFlag {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let start = r#if(|c: &char| c.is_ascii_alphanumeric());
|
let start = r#if(|c: &char| c.is_ascii_alphanumeric());
|
||||||
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_@-".contains(*c)).repeated(0..);
|
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_@-".contains(*c))
|
||||||
|
.repeated()
|
||||||
|
.many();
|
||||||
|
|
||||||
start
|
start
|
||||||
.and(rest)
|
.and(rest)
|
||||||
|
|||||||
Reference in New Issue
Block a user