summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-13 23:02:40 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-13 23:03:04 +0000
commitd3085968d3913781ea6c19251a1d9170f09e018c (patch)
treeac98dacca13ad2d9c7e9a09f7d7601605e876286
parent3d4b4babaac3f9624308e9ae3eab3a15134e2ed1 (diff)
downloadmon-d3085968d3913781ea6c19251a1d9170f09e018c.tar.gz
make alpha, numeric, alphanumeric, and whitespace return I::Item
-rw-r--r--src/lib.rs22
-rw-r--r--tests/sexpr.rs4
2 files changed, 7 insertions, 19 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d96eb4c..013782f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -995,15 +995,12 @@ where
Eof
}
-pub fn alpha<I>() -> impl Parser<I, Output = I>
+pub fn alpha<I>() -> impl Parser<I, Output = I::Item>
where
I: Input,
I::Item: Character,
{
r#if(|c: &I::Item| c.is_alphabetic())
- .repeated()
- .many()
- .recognize()
}
pub fn alpha1<I>() -> impl Parser<I, Output = I>
@@ -1017,15 +1014,12 @@ where
.recognize()
}
-pub fn numeric<I>() -> impl Parser<I, Output = I>
+pub fn numeric<I>() -> impl Parser<I, Output = I::Item>
where
I: Input,
I::Item: Character,
{
r#if(|c: &I::Item| c.is_numeric())
- .repeated()
- .many()
- .recognize()
}
pub fn numeric1<I>() -> impl Parser<I, Output = I>
@@ -1039,15 +1033,12 @@ where
.recognize()
}
-pub fn alphanumeric<I>() -> impl Parser<I, Output = I>
+pub fn alphanumeric<I>() -> impl Parser<I, Output = I::Item>
where
I: Input,
I::Item: Character,
{
r#if(|c: &I::Item| c.is_alphanumeric())
- .repeated()
- .many()
- .recognize()
}
pub fn alphanumeric1<I>() -> impl Parser<I, Output = I>
@@ -1061,15 +1052,12 @@ where
.recognize()
}
-pub fn whitespace<I>() -> impl Parser<I, Output = I>
+pub fn whitespace<I>() -> impl Parser<I, Output = I::Item>
where
I: Input,
I::Item: Character,
{
r#if(|c: &I::Item| c.is_whitespace())
- .repeated()
- .many()
- .recognize()
}
pub fn whitespace1<I>() -> impl Parser<I, Output = I>
@@ -1129,7 +1117,7 @@ mod test {
let input = "a b c";
let it = InputIter::new(input);
- alpha1()
+ alpha()
.separated_by(whitespace())
.at_least(1)
.check_finished(it)
diff --git a/tests/sexpr.rs b/tests/sexpr.rs
index 8d02793..1f8a0af 100644
--- a/tests/sexpr.rs
+++ b/tests/sexpr.rs
@@ -15,7 +15,7 @@ enum Sexpr {
fn atom<'a>() -> impl Parser<&'a str, Output = Sexpr> {
alpha1()
- .and(alphanumeric())
+ .and(alphanumeric().repeated().many())
.recognize()
.map(|output: &str| Sexpr::Atom(output.to_string()))
}
@@ -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_by(whitespace())
+ .separated_by(whitespace().repeated().many())
.many()
.delimited_by(tag("("), tag(")"))
.map(|output| Sexpr::List(output))