Skip to content

How to hold Prefix correctly? #373

Answered by gmedori
gmedori asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, finally a solution:

Since I have a custom conversion adding in quotes to the printed value, I need to symmetrically remove the quotes inside the conversion, rather than omitting them entirely from the parser. Here's the code that fixed everything:

First we surround the entire contents of the parser with Consumed so the void-returning string literal parsers are now included in the substring passed to the conversion:

struct QuotedSearchTermParser: ParserPrinter {
  var body: some ParserPrinter<Substring, SearchTerm> {
    Parse(SearchTermConversion(isQuoted: true)) {
      // NEW
      Consumed {
        "\""
        Prefix { $0 != "\"" }
        "\""
      }
    }
  }
}

Then we update …

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by gmedori
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