Skip to content

Unable to start a line with an Int parser #310

Answered by mbrandonw
sbeitzel asked this question in Q&A
Discussion options

You must be logged in to vote

You need to supply more type information due to certain limitations of result builders in Swift. This was detailed in this discussion.

To fix you can either do this:

let pairParser = Parse.init(input: Substring.self, ElfPair.init) {
  Int.parser()
  "-"
  Int.parser()
  ","
  Int.parser()
  "-"
  Int.parser()
}

Or you can define a whole new parser type using the body-style of parsing, which can be easier for the compiler to process for large, complex parsers:

struct ElfPairParser: Parser {
  var body: some Parser<Substring, ElfPair> {
    Parse(ElfPair.init) {
      Int.parser()
      "-"
      Int.parser()
      ","
      Int.parser()
      "-"
      Int.parser()
    }
  }
}

Also this is…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sbeitzel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #309 on August 08, 2023 23:44.