pointfreeco/swift-parsing

Support for inline replace

bielikb opened this issue · 0 comments

Hey folks,

this is a feature request that in terms of responsibilities of this library might be a bit out of the topic. Yet Id like to understand your view on the following:

Problem statement

Currently there's no out-of-the-box Parser (that Im aware of) to support the replace functionality.

Example:

  1. Parse version
    version = 1.0.0

  2. Replace the parsed version
    version = 2.0.0

Expected Result:

Pseudo code:

  • Take the input string that contains semantic version number
  • Skip up to the semantic version number
  • Read the major version number sequence and replace it with newer value

The API could look somehow like this (no strong opinions here as Im more interested in the functionality).

Call site

Skip(PrefixThrough<Substring>("version = "[...]))
    .replace(PrefixUpTo<Substring>("."), with: Write("2"))

If there's already possibility to achieve the replace functionality, I'm open to suggestions.

Thanks!