update parsers to use the ParserIter trait from mon

This commit is contained in:
John Turner
2025-11-01 17:28:19 +00:00
parent 6b04125d14
commit a38b01cd04
5 changed files with 53 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
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::{
Parseable,
@@ -74,8 +74,8 @@ impl<'a> Parseable<'a, &'a str> for Version {
type Parser = impl Parser<&'a str, Output = Self>;
fn parser() -> Self::Parser {
let numbers = VersionNumber::parser().separated_by(tag("."), 1..);
let suffixes = VersionSuffix::parser().separated_by(tag("_"), 0..);
let numbers = VersionNumber::parser().separated_by(tag(".")).at_least(1);
let suffixes = VersionSuffix::parser().separated_by(tag("_")).many();
let rev = VersionNumber::parser().preceded_by(tag("-r"));
numbers
@@ -96,7 +96,9 @@ impl<'a> Parseable<'a, &'a str> for Category {
fn parser() -> Self::Parser {
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
.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(),
)),
)
.repeated(0..);
.repeated()
.many();
start
.and(rest)
@@ -140,7 +143,9 @@ impl<'a> Parseable<'a, &'a str> for SlotName {
fn parser() -> Self::Parser {
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
.and(rest)
@@ -257,7 +262,8 @@ impl<'a> Parseable<'a, &'a str> for Atom {
.and(Slot::parser().preceded_by(tag(":")).opt())
.and(
UseDep::parser()
.separated_by(tag(","), 0..)
.separated_by(tag(","))
.many()
.delimited_by(tag("["), tag("]"))
.opt(),
)