Add TakeWhile and TakeWhile1 combinators
oleiade opened this issue · comments
Théo Crevon commented
The library should have some version of a TakeWhile
and/or TakeWhile1
character parser combinators.
TakeWhile
The combinator would return the longest continuous subset of the input that matched the provided predicate. It would likely have a prototype such as:
func TakeWhile[Input Bytes](input Input, predicate func(input rune)bool) gomme.Parser[Input, Input]
and be used like:
func separator() gomme.Parser[string, string] {
return gomme.TakeWhile[string](isSeparator)
}
func isSeparator(c rune) bool {
return c == '\t' || c == '\r' || c == '\n'
}
TakeWhile1
Would fulfill the same contract as above, with the added condition that the predicate should be matched at least once.