oleiade / gomme

Parser combinator library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add TakeWhile and TakeWhile1 combinators

oleiade opened this issue · 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.