You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of a parser I am writing, I would like to define something that expects at least one multispace and can include line-ended comments. I would like to collect the comments into a Vec.
To accomplish this, I was looking for a multi combinator that would let me collect only certain values. I found fold_many1 and used it as follows:
fnpush_some<T>(mutacc:Vec<T>,item:Option<T>) -> Vec<T>{ifletSome(item) = item {
acc.push(item);}
acc
}fncomment<'a,E:ParseError<&'a str>>(input:&'a str) -> IResult<&'a str,&'a str,E>{preceded(char('#'),is_not("\n\r"))(input)}// At least 1 multispace or comment, outputs the comment contents if possible.fnspace_or_comment(input:&str) -> IResult<&str,Option<&str>>{alt((value(None, multispace1),map(comment,Some),))(input)}fnspacing1(input:&str) -> IResult<&str,Vec<&str>>{fold_many1(space_or_comment,Vec::default, push_some)(input)}
I was wondering if it made sense to have combinators filter_many0 and filter_many1 defined as :
As part of a parser I am writing, I would like to define something that expects at least one
multispace
and can include line-ended comments. I would like to collect the comments into a Vec.To accomplish this, I was looking for a multi combinator that would let me collect only certain values. I found
fold_many1
and used it as follows:I was wondering if it made sense to have combinators
filter_many0
andfilter_many1
defined as :With these combinators, I could write:
Perhaps there is a better way to think about the problem and I don't actually need this.
The text was updated successfully, but these errors were encountered: