Skip to content

Commit

Permalink
make parse more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
figsoda committed Feb 18, 2023
1 parent 4508dbf commit 3696e9d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ use chumsky::{
prelude::Simple,
primitive::{choice, end, filter, just},
recursive::recursive,
Error, Parser,
Error, Parser, Stream,
};

use std::ops::Range;

use crate::macros::set;

/// Python dependency specified by [PEP 508](https://peps.python.org/pep-0508)
Expand Down Expand Up @@ -125,8 +127,15 @@ pub enum Comparator {
}

/// Parse a [PEP 508](https://peps.python.org/pep-0508) string into a [Dependency]
pub fn parse(s: &str) -> Result<Dependency, Vec<Simple<char>>> {
parser().then_ignore(end()).parse(s)
/// ```
/// # use pep_508::parse;
/// assert_eq!(parse("requests >= 2").unwrap().name, "requests");
/// assert_eq!(parse(String::from("numpy")).unwrap().name, "numpy");
/// ```
pub fn parse<'a, I: Iterator<Item = (char, Range<usize>)> + 'a>(
dependency: impl Into<Stream<'a, char, Range<usize>, I>>,
) -> Result<Dependency, Vec<Simple<char>>> {
parser().then_ignore(end()).parse(dependency)
}

/// Create a [chumsky](https://docs.rs/chumsky) parser,
Expand Down

0 comments on commit 3696e9d

Please sign in to comment.