Here’s one (of possibly many solutions).
Just use terminated
along with opt
:
pub fn parse_list(input: &str) -> IResult<&str, Vec<&str>> {
delimited(
ws(tag("[")),
terminated(
separated_list0(
ws(tag(",")),
take_while1(|x| char::is_alphabetic(x) || x == '_'),
),
opt(ws(tag(","))),
),
ws(tag("]")),
)(input)
}
CLICK HERE to find out more related problems solutions.