Skip to content

Add an Escaped character parser combinator  #6

Description

@oleiade

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions