From 821f132bd5c8678327c2ab8764bd7d172a7b7ee4 Mon Sep 17 00:00:00 2001 From: John Turner Date: Thu, 30 Oct 2025 22:33:02 +0000 Subject: rename List to Repeated and SeparatedList to SeparatedBy --- src/lib.rs | 42 +++++++++++++++++++++++++----------------- tests/sexpr.rs | 2 +- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5d6f0cc..250ce9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,11 +153,11 @@ pub trait Parser: Sized { Recognize { parser: self } } - fn list(self, range: R) -> impl Parser> + fn repeated(self, range: R) -> impl Parser> where R: RangeBounds, { - List { + Repeated { parser: self, range, } @@ -195,7 +195,7 @@ pub trait Parser: Sized { Not { parser: self } } - fn separated_list( + fn separated_by( self, delimiter: P, range: R, @@ -204,7 +204,7 @@ pub trait Parser: Sized { P: Parser, R: RangeBounds, { - SeparatedList { + SeparatedBy { parser: self, delimiter, range, @@ -387,12 +387,12 @@ where Take { amt } } -struct List { +struct Repeated { parser: P, range: R, } -impl Parser for List +impl Parser for Repeated where I: Input, P: Parser, @@ -429,13 +429,13 @@ where } } -struct SeparatedList { +struct SeparatedBy { parser: P1, delimiter: P2, range: R, } -impl Parser for SeparatedList +impl Parser for SeparatedBy where I: Input, P1: Parser, @@ -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() -> impl Parser @@ -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() -> impl Parser @@ -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() -> impl Parser @@ -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() -> impl Parser @@ -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() -> impl Parser @@ -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() -> impl Parser @@ -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()) -- cgit v1.2.3