Terminated list helper
diff --git a/src/helper.rs b/src/helper.rs
index cc08c9a..734299d 100644
--- a/src/helper.rs
+++ b/src/helper.rs
@@ -84,11 +84,22 @@
macro_rules! separated_list {
($i:expr, punct!($sep:expr), $f:expr) => {
- $crate::helper::separated_list($i, $sep, $f)
+ $crate::helper::separated_list($i, $sep, $f, false)
};
}
-pub fn separated_list<'a, T>(mut input: &'a str, sep: &'static str, f: fn(&'a str) -> IResult<&'a str, T>) -> IResult<&'a str, Vec<T>> {
+macro_rules! terminated_list {
+ ($i:expr, punct!($sep:expr), $f:expr) => {
+ $crate::helper::separated_list($i, $sep, $f, true)
+ };
+}
+
+pub fn separated_list<'a, T>(
+ mut input: &'a str,
+ sep: &'static str,
+ f: fn(&'a str) -> IResult<&'a str, T>,
+ terminated: bool,
+) -> IResult<&'a str, Vec<T>> {
let mut res = Vec::new();
// get the first element
@@ -118,6 +129,11 @@
break;
}
}
+ if terminated {
+ if let IResult::Done(after, _) = punct(input, sep) {
+ input = after;
+ }
+ }
IResult::Done(input, res)
}
}