packaging a parsing into a struct #239
Unanswered
JaapWijnen
asked this question in
Q&A
Replies: 1 comment 2 replies
-
This is probably the most ergonomic way of handling the problem right now. There is a slight cost at the point of erasure, but you should always benchmark before considering it a showstopper. Swift 5.7 comes with some very powerful new generics features that will simplify this via The future is bright, though! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I recently wrote an xml parser using the parsing package. currently it lives in the form of a closure
let xmlParser: (Bool) -> AnyParser<Substring.UTF8View, XML>
where the bool indicates if you want to print using indentation/pretty or just flattened xml, and the XML is my XML type to parse into.
I want to package this into a struct so I can make the api a little bit cleaner:
I'm not entirely sure how to go about packaging it into a struct though since my parser uses a property (the boolean) to decide its behaviour. I currently think I can do two things:
Both methods would require writing the whole parser type out for these properties (which is an incredibly long nested type), I could of course use .eraseToAnyParser() but I'm not sure if there's any cost involved with that?
Any advice on what way to go?
My parser looks like this:
so because of the use of the indenting variable I can't just do the following on init unfortunately
Beta Was this translation helpful? Give feedback.
All reactions