Skip to content
Discussion options

You must be logged in to vote

Figured this out myself by looking at how string parsing worked in the JSON example. Ended up using Many for character-by-character iteration (not optimized at all):

func parenParser() -> AnyParser<Substring, Substring> {
    Parse {
        "("
        Many(into: Substring("")) { string, fragment in
            string += fragment
        } element: {
            OneOf {
                Prefix(1...) { $0 != "(" && $0 != ")" }

                Lazy { parenParser() }
            }
        } terminator: {
            ")"
        }
    }
    .eraseToAnyParser()
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Tyler-Keith-Thompson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant