aboutsummaryrefslogtreecommitdiff
path: root/helix-parsec
diff options
context:
space:
mode:
Diffstat (limited to 'helix-parsec')
-rw-r--r--helix-parsec/src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/helix-parsec/src/lib.rs b/helix-parsec/src/lib.rs
index e09814b8..846d02d6 100644
--- a/helix-parsec/src/lib.rs
+++ b/helix-parsec/src/lib.rs
@@ -459,6 +459,7 @@ pub fn zero_or_more<'a, P, T>(parser: P) -> impl Parser<'a, Output = Vec<T>>
where
P: Parser<'a, Output = T>,
{
+ let parser = non_empty(parser);
move |mut input| {
let mut values = Vec::new();
@@ -491,6 +492,7 @@ pub fn one_or_more<'a, P, T>(parser: P) -> impl Parser<'a, Output = Vec<T>>
where
P: Parser<'a, Output = T>,
{
+ let parser = non_empty(parser);
move |mut input| {
let mut values = Vec::new();
@@ -559,3 +561,14 @@ where
Ok((input, values))
}
}
+
+pub fn non_empty<'a, T>(p: impl Parser<'a, Output = T>) -> impl Parser<'a, Output = T> {
+ move |input| {
+ let (new_input, res) = p.parse(input)?;
+ if new_input.len() == input.len() {
+ Err(input)
+ } else {
+ Ok((new_input, res))
+ }
+ }
+}