-
If this is the wrong place to ask a question about how to work with the parsing package, please let me know where to redirect. I've set up a parser (everything has been simplified for reproducibility) that depends upon an item: public enum Item {
case item1(Substring)
case item2(Substring)
case item3(Substring, Substring)
} I've written a handful of parsers in this format: let parseAnItemTwo = Parse(Item.item2) {
"@@ "
Prefix { $0 != "\n" }
"\n" So far so good. I can hand roll the parsing of a given string when I specify them in the correct order. But I want to use something similar to OneOf (or an equivalent conditional) to parse a stream of tokens from the input (resulting in Array) let fullSuite = OneOf {
parseAnItemOne
parseAnItemTwo
parseAnItemThree
}
} I would then run this on my input, which works fine as long as I have a newline between each token
I need the separator to be optional (there might be newlines between records/tokens, but it's not a requirement). I tried revising your zeroOrMoreSpaces: let zeroOrMoreNewlines = Prefix { $0 == "\n" }
let iterateForTokens = Many {
fullSuite
} separator: {
zeroOrMoreNewlines
} This compiles, but produces a run-time error:
Again: All tokens in the input stream have unique starting sequences, so explicit delimiters aren't required in the data stream. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you provide a little more context for folks to help troubleshoot? Full, compiling code for the parser would help, as well as some sample input that fails? You also might get a better error message if you print it as a string: do {
try parser.parse(input)
} catch {
print("\(error)")
} Ideally this would be printed automatically, though. Can you let us know how you're getting the error printed like that? Are you invoking this as an executable on the command line, or? |
Beta Was this translation helpful? Give feedback.
-
It looks like I can't mark a comment reply as an answer, so let me just say that @haikusw has answered my question. |
Beta Was this translation helpful? Give feedback.
It looks like I can't mark a comment reply as an answer, so let me just say that @haikusw has answered my question.
Thank you both for your time 🙏🏻