gomme icon indicating copy to clipboard operation
gomme copied to clipboard

Add an `Escaped` character parser combinator

Open oleiade opened this issue 3 years ago • 0 comments

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"
}

oleiade avatar Sep 08 '22 06:09 oleiade