gomme
gomme copied to clipboard
Add an `Escaped` character parser combinator
As we've been implementing an example JSON parser, we encountered the need to manage "escaped" strings.
Go strings are escaped, and when parsing the following string: {"abc": "123"}, it is interpreted as {\"abc\": \"123\"}.
Its prototype would probably be:
func Escaped[I Bytes, PO, EO any](parse Parser[I, PO], control rune, escape Parser[I, EO]) Result[I, I]
And would behave in the following way:
func main() {
result := Escaped(Alpha1(), '\\', OneOf(""n\"))("\"abc\"")
result.Output == "abc"
}