Parses a full [`SourceUrl`] from a string slice.
(input: &mut &str)
| 254 | format!("{prefix}+") |
| 255 | } else { |
| 256 | String::new() |
| 257 | }; |
| 258 | |
| 259 | write!(f, "{prefix}{url}{query}{formatted_fragment}",) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /// For SourceUrl, we only define a [`ParserUntil`] trait and not the `AlpmParser` trait, as we |
| 264 | /// don't provide the [`Url`] type parser ourselves. Hence, the indicator for its supposed "end" |
| 265 | /// must be provided by the caller of the parser. |
| 266 | impl ParserUntil for SourceUrl { |
| 267 | /// Recognizes an [`SourceUrl`] in an input string until a given `delimiter`. |
| 268 | /// |
| 269 | /// # Errors |
| 270 | /// |
| 271 | /// Returns an error if `input` does not begin with a valid [`SourceUrl`], followed by the |
| 272 | /// specified `delimiter`. |
| 273 | fn parser_until<'a, P>(delimiter: P) -> impl Parser<Input<'a>, Self, ErrMode<ParseStack<'a>>> |
| 274 | where |
| 275 | P: Parser<Input<'a>, &'a str, ErrMode<ParseStack<'a>>>, |
| 276 | { |
| 277 | // Define the actual parser closure. |
| 278 | // The delimiter is moved into the closure and borrowed via `by_ref()` on each call. |
| 279 | let mut delimiter = delimiter; |
| 280 | let parser = move |input: &mut Input<'a>| -> PResult<Self> { |
| 281 | // Check if we should use a VCS for this URL. |
| 282 | let vcs = opt(VcsProtocol::parser).parse_next(input)?; |
| 283 | |
| 284 | let Some(vcs) = vcs else { |
| 285 | // If there's no VCS, interpret everything up to the delimiter as a URL. |
| 286 | // |
| 287 | // We explicitly don't look for ALPM related fragments or queries, as the fragment |
| 288 | // and query might be a part of the inner URL string for retrieving |
| 289 | // the sources. |
| 290 | let url = repeat_till::<_, _, (), _, _, _, _>(0.., any, peek(delimiter.by_ref())) |
| 291 | .take() |
| 292 | .try_map(Url::from_str) |
| 293 | .layer("url") |
| 294 | .parse_next(input)?; |
| 295 | return Ok(SourceUrl { |
| 296 | url, |
| 297 | vcs_info: None, |
| 298 | }); |
| 299 | }; |
| 300 | |
| 301 | // We now know that we look at a URL that's supposed to be used by a VCS. |
| 302 | // Get the URL first, error if we cannot find it. |
| 303 | // Recognizes a URL in an alpm-package-source string. |
| 304 | // |
| 305 | // Considers all chars until a special char or the EOF is encountered: |
| 306 | // - `#` character that indicates a fragment |