build-id must not start with zero

This commit is contained in:
2025-11-21 04:33:55 +00:00
parent bf56ed1c61
commit fb69d82e6f
2 changed files with 47 additions and 8 deletions

View File

@@ -1,15 +1,15 @@
use core::option::Option::None;
use mon::{
Parser, ParserIter, ascii_alphanumeric, ascii_numeric1, eof, r#if, input::InputIter, one_of,
tag,
Parser, ParserIter, ascii_alphanumeric, ascii_numeric, ascii_numeric1, eof, r#if,
input::InputIter, one_of, tag,
};
use crate::{
Parseable,
atom::{
Atom, Blocker, Category, Cp, Cpv, Name, Repo, Slot, SlotName, SlotOperator, UseDep,
UseDepCondition, UseDepNegate, UseDepSign, Version, VersionNumber, VersionNumbers,
Atom, Blocker, BuildId, Category, Cp, Cpv, Name, Repo, Slot, SlotName, SlotOperator,
UseDep, UseDepCondition, UseDepNegate, UseDepSign, Version, VersionNumber, VersionNumbers,
VersionOperator, VersionSuffix, VersionSuffixKind, VersionSuffixes, Wildcard,
},
useflag::UseFlag,
@@ -47,6 +47,20 @@ impl<'a> Parseable<'a, &'a str> for VersionNumber {
}
}
impl<'a> Parseable<'a, &'a str> for BuildId {
type Parser = impl Parser<&'a str, Output = Self>;
fn parser() -> Self::Parser {
let start = ascii_numeric().and_not(tag("0"));
let rest = ascii_numeric().repeated().many();
start
.and(rest)
.recognize()
.map(|output: &str| BuildId(output.to_string()))
}
}
impl<'a> Parseable<'a, &'a str> for VersionSuffixKind {
type Parser = impl Parser<&'a str, Output = Self>;
@@ -97,7 +111,7 @@ impl<'a> Parseable<'a, &'a str> for Version {
fn parser() -> Self::Parser {
let rev = VersionNumber::parser().preceded_by(tag("-r"));
let build_id = VersionNumber::parser().preceded_by(tag("-"));
let build_id = BuildId::parser().preceded_by(tag("-"));
VersionNumbers::parser()
.and(r#if(|c: &char| c.is_ascii_alphabetic() && c.is_ascii_lowercase()).opt())