Parsing to dictionaries
JaapWijnen opened this issue · 0 comments
JaapWijnen commented
Hi! I've been doing some xml related parsing recently and I run into an issue when parsing attributes such as:
<xmlTag "attr1"="value1" "attr2"="value2" />
When parsing these to a dictionary round tripping wil occasionally fail since dictionaries are unordered so the printed order will be reversed for example.
So I switched to swift-collections' OrderedDictionary
which fixed the problem.
A few of swift-collections' types don't conform to collection however due to protocol requirement clashes with subscripts I believe.
Specifically the End()
parser requires Input to conform to Collection. Summarising I have two questions:
- Are there better ways to get around my ordered dictionary problem with xml/html attributes?
- Could we loosen the restrictions on the
End
parser to Sequence?
Something like this seems to work in this case:
struct SequenceEnd<Input: Sequence>: Parser {
func parse(_ input: inout Input) throws {
var iterator = input.makeIterator()
guard iterator.next() == nil else {
throw SomeError()
}
}
}
Let me know what you think!