Skip to content

Add TakeWhile and TakeWhile1 combinators #2

Description

@oleiade

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions