gomme icon indicating copy to clipboard operation
gomme copied to clipboard

Add TakeWhile and TakeWhile1 combinators

Open oleiade opened this issue 3 years ago • 0 comments

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.

oleiade avatar Sep 07 '22 14:09 oleiade