diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-10-30 22:33:02 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-10-30 22:33:02 +0000 |
| commit | 821f132bd5c8678327c2ab8764bd7d172a7b7ee4 (patch) | |
| tree | b0a4acd9c6ad09bb8d04482ff0ba774f17347d9f | |
| parent | 3eb3db5bda48fa975e5651f3fd7122b86886783b (diff) | |
| download | mon-821f132bd5c8678327c2ab8764bd7d172a7b7ee4.tar.gz | |
rename List to Repeated and SeparatedList to SeparatedBy
| -rw-r--r-- | src/lib.rs | 42 | ||||
| -rw-r--r-- | tests/sexpr.rs | 2 |
2 files changed, 26 insertions, 18 deletions
@@ -153,11 +153,11 @@ pub trait Parser<I: Input>: Sized { Recognize { parser: self } } - fn list<R>(self, range: R) -> impl Parser<I, Output = Vec<Self::Output>> + fn repeated<R>(self, range: R) -> impl Parser<I, Output = Vec<Self::Output>> where R: RangeBounds<usize>, { - List { + Repeated { parser: self, range, } @@ -195,7 +195,7 @@ pub trait Parser<I: Input>: Sized { Not { parser: self } } - fn separated_list<P, R>( + fn separated_by<P, R>( self, delimiter: P, range: R, @@ -204,7 +204,7 @@ pub trait Parser<I: Input>: Sized { P: Parser<I>, R: RangeBounds<usize>, { - SeparatedList { + SeparatedBy { parser: self, delimiter, range, @@ -387,12 +387,12 @@ where Take { amt } } -struct List<P, R> { +struct Repeated<P, R> { parser: P, range: R, } -impl<I, P, R> Parser<I> for List<P, R> +impl<I, P, R> Parser<I> for Repeated<P, R> where I: Input, P: Parser<I>, @@ -429,13 +429,13 @@ where } } -struct SeparatedList<P1, P2, R> { +struct SeparatedBy<P1, P2, R> { parser: P1, delimiter: P2, range: R, } -impl<I, P1, P2, R> Parser<I> for SeparatedList<P1, P2, R> +impl<I, P1, P2, R> Parser<I> for SeparatedBy<P1, P2, R> where I: Input, P1: Parser<I>, @@ -860,7 +860,9 @@ where I: Input, I::Item: Character, { - r#if(|c: &I::Item| c.is_alphabetic()).list(0..).recognize() + r#if(|c: &I::Item| c.is_alphabetic()) + .repeated(0..) + .recognize() } pub fn alpha1<I>() -> impl Parser<I, Output = I> @@ -868,7 +870,9 @@ where I: Input, I::Item: Character, { - r#if(|c: &I::Item| c.is_alphabetic()).list(1..).recognize() + r#if(|c: &I::Item| c.is_alphabetic()) + .repeated(1..) + .recognize() } pub fn numeric<I>() -> impl Parser<I, Output = I> @@ -876,7 +880,7 @@ where I: Input, I::Item: Character, { - r#if(|c: &I::Item| c.is_numeric()).list(0..).recognize() + r#if(|c: &I::Item| c.is_numeric()).repeated(0..).recognize() } pub fn numeric1<I>() -> impl Parser<I, Output = I> @@ -884,7 +888,7 @@ where I: Input, I::Item: Character, { - r#if(|c: &I::Item| c.is_numeric()).list(1..).recognize() + r#if(|c: &I::Item| c.is_numeric()).repeated(1..).recognize() } pub fn alphanumeric<I>() -> impl Parser<I, Output = I> @@ -893,7 +897,7 @@ where I::Item: Character, { r#if(|c: &I::Item| c.is_alphanumeric()) - .list(0..) + .repeated(0..) .recognize() } @@ -903,7 +907,7 @@ where I::Item: Character, { r#if(|c: &I::Item| c.is_alphanumeric()) - .list(1..) + .repeated(1..) .recognize() } @@ -912,7 +916,9 @@ where I: Input, I::Item: Character, { - r#if(|c: &I::Item| c.is_whitespace()).list(0..).recognize() + r#if(|c: &I::Item| c.is_whitespace()) + .repeated(0..) + .recognize() } pub fn whitespace1<I>() -> impl Parser<I, Output = I> @@ -920,7 +926,9 @@ where I: Input, I::Item: Character, { - r#if(|c: &I::Item| c.is_whitespace()).list(1..).recognize() + r#if(|c: &I::Item| c.is_whitespace()) + .repeated(1..) + .recognize() } pub fn any<I>() -> impl Parser<I, Output = I::Item> @@ -969,7 +977,7 @@ mod test { let it = InputIter::new(input); alpha1() - .separated_list(whitespace(), 1..) + .separated_by(whitespace(), 1..) .check_finished(it) .unwrap(); } diff --git a/tests/sexpr.rs b/tests/sexpr.rs index e5024ef..ecef773 100644 --- a/tests/sexpr.rs +++ b/tests/sexpr.rs @@ -35,7 +35,7 @@ fn int<'a>() -> impl Parser<&'a str, Output = Sexpr> { fn sexpr<'a>() -> impl Parser<&'a str, Output = Sexpr> { |it| { sexpr() - .separated_list(whitespace(), 0..) + .separated_by(whitespace(), 0..) .delimited_by(tag("("), tag(")")) .map(|output| Sexpr::List(output)) .or(atom()) |
