summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-14 20:04:27 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-14 20:04:27 +0000
commite6c5335d43bfbf2fffa3d3c44cde404c970e5ee6 (patch)
tree20636011c4c529c459f35563492aeba67aa4e4d3
parent73eec22d62291a8cf6c095e1bdb74e83a01c759d (diff)
downloadmon-e6c5335d43bfbf2fffa3d3c44cde404c970e5ee6.tar.gz
disallow trailing delimiter in SeparatedBy combinator
-rw-r--r--src/lib.rs19
-rw-r--r--tests/sexpr.rs4
2 files changed, 20 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index acf2dcc..7c1bbcc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -262,7 +262,10 @@ where
};
let rest = match self.delimiter.check(rest.clone()) {
- Ok((rest, _)) => rest,
+ Ok((rest, _)) => match self.parser.check(rest.clone()) {
+ Ok(_) => rest,
+ Err(_) => return Some(Err(EM::bind(|| rest))),
+ },
_ => rest,
};
@@ -1030,6 +1033,20 @@ mod test {
}
#[test]
+ fn test_separated_list_with_trailing_delimiter() {
+ let input = "1.0.";
+ let it = InputIter::new(input);
+
+ assert!(
+ numeric1()
+ .separated_by(tag("."))
+ .at_least(1)
+ .check_finished(it)
+ .is_err()
+ );
+ }
+
+ #[test]
fn test_find() {
let input = "hello world";
let it = InputIter::new(input);
diff --git a/tests/sexpr.rs b/tests/sexpr.rs
index 1f8a0af..77ef3a0 100644
--- a/tests/sexpr.rs
+++ b/tests/sexpr.rs
@@ -2,7 +2,7 @@
use mon::{
Parser, ParserIter, alpha1, alphanumeric, alphanumeric1, input::InputIter, numeric1, tag,
- whitespace,
+ whitespace, whitespace1,
};
#[derive(Debug)]
@@ -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().repeated().many())
+ .separated_by(whitespace1())
.many()
.delimited_by(tag("("), tag(")"))
.map(|output| Sexpr::List(output))