Skip to content

Merging parsers that consume entire input #84

Answered by ph1ps
StefanCosminR asked this question in Q&A
Discussion options

You must be logged in to vote

My (naive) approach would be to just pipe the component parsers down a couple of PrefixUpTo parsers like this:

let input = "Endpoint=sb://organization-name.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=3252389randomCharacters43242380=09=/="

let endpointParser = StartsWith("Endpoint=sb")
  .take(Rest())
  .map { "https" + $0 }

let sasKeyNameParser = StartsWith("SharedAccessKeyName=")
  .take(Rest())

let sasKeyValueParser = StartsWith("SharedAccessKey=")
  .take(Rest())

let parser = PrefixUpTo(";")
  .pipe(endpointParser)
  .skip(";")
  .take(
    PrefixUpTo(";")
      .pipe(sasKeyNameParser)
      .skip(";")
  )
  .take(
    sasKeyValueP…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@StefanCosminR
Comment options

Answer selected by StefanCosminR
Comment options

You must be logged in to vote
2 replies
@StefanCosminR
Comment options

@tgrapperon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants