use new mon parsers

This commit is contained in:
John Turner
2025-11-13 23:21:46 +00:00
parent 58b4592b7b
commit 50ab68c9c5
3 changed files with 23 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
use core::option::Option::None; use core::option::Option::None;
use mon::{Parser, ParserIter, r#if, numeric1, one_of, tag}; use mon::{Parser, ParserIter, alphanumeric, r#if, numeric1, one_of, tag};
use crate::{ use crate::{
Parseable, Parseable,
@@ -115,10 +115,8 @@ impl<'a> Parseable<'a, &'a str> for Category {
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 start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_'); let start = alphanumeric().or(one_of("_".chars()));
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)) let rest = alphanumeric().or(one_of("+_.-".chars())).repeated().many();
.repeated()
.many();
start start
.and(rest) .and(rest)
@@ -131,13 +129,15 @@ impl<'a> Parseable<'a, &'a str> for Name {
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 start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_'); let start = alphanumeric().or(one_of("_".chars()));
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "_+".contains(*c))
.or( let rest = alphanumeric()
one_of("-".chars()).and_not(Version::parser().preceded_by(tag("-")).followed_by( .or(one_of("_+".chars()))
r#if(|c: &char| c.is_ascii_alphanumeric() || "_+-".contains(*c)).not(), .or(one_of("-".chars()).and_not(
)), Version::parser()
) .preceded_by(tag("-"))
.followed_by(alphanumeric().or(one_of("_+-".chars())).not()),
))
.repeated() .repeated()
.many(); .many();
@@ -162,10 +162,8 @@ impl<'a> Parseable<'a, &'a str> for SlotName {
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 start = r#if(|c: &char| c.is_ascii_alphanumeric() || *c == '_'); let start = alphanumeric().or(one_of("_".chars()));
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)) let rest = alphanumeric().or(one_of("+_.-".chars())).repeated().many();
.repeated()
.many();
start start
.and(rest) .and(rest)

View File

@@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use mon::{Parser, ParserIter, alpha1, r#if, tag, whitespace1}; use mon::{Parser, ParserIter, alpha1, alphanumeric, r#if, one_of, tag, whitespace1};
use crate::{ use crate::{
Parseable, Parseable,
@@ -48,6 +48,7 @@ impl<'a> Parseable<'a, &'a str> for SrcUri {
.recognize() .recognize()
.map(|output: &str| PathBuf::from(output)) .map(|output: &str| PathBuf::from(output))
}; };
let uri = UriPrefix::parser() let uri = UriPrefix::parser()
.opt() .opt()
.and(Uri::parser()) .and(Uri::parser())
@@ -66,10 +67,8 @@ impl<'a> Parseable<'a, &'a str> for License {
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 start = r#if(|c: &char| c.is_ascii_alphanumeric() || "_".contains(*c)); let start = alphanumeric().or(one_of("_".chars()));
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)) let rest = alphanumeric().or(one_of("+_.-".chars())).repeated().many();
.repeated()
.many();
start start
.and(rest) .and(rest)
@@ -82,10 +81,8 @@ impl<'a> Parseable<'a, &'a str> for Eapi {
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 start = r#if(|c: &char| c.is_ascii_alphanumeric() || "_".contains(*c)); let start = alphanumeric().or(one_of("_".chars()));
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_.-".contains(*c)) let rest = alphanumeric().or(one_of("+_.-".chars())).repeated().many();
.repeated()
.many();
start start
.and(rest) .and(rest)

View File

@@ -1,4 +1,4 @@
use mon::{Parser, ParserIter, r#if, tag}; use mon::{Parser, ParserIter, alphanumeric, one_of, tag};
use crate::{ use crate::{
Parseable, Parseable,
@@ -9,10 +9,8 @@ impl<'a> Parseable<'a, &'a str> for UseFlag {
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 start = r#if(|c: &char| c.is_ascii_alphanumeric()); let start = alphanumeric();
let rest = r#if(|c: &char| c.is_ascii_alphanumeric() || "+_@-".contains(*c)) let rest = alphanumeric().or(one_of("+_@-".chars())).repeated().many();
.repeated()
.many();
start start
.and(rest) .and(rest)