# Declarative String Processing Overview

**URL:** <https://forums.swift.org/t/declarative-string-processing-overview/52459>\
**Category:** Pitches\
**Created:** [September 29, 2021, 11:13pm UTC](https://forums.swift.org/t/declarative-string-processing-overview/52459 "2021-09-29T23:13:12Z")\
**Posts on this page:** 1\
**Showing post:** 119

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [October 14, 2021, 5:02pm UTC](https://forums.swift.org/t/declarative-string-processing-overview/52459/119 "2021-10-14T17:02:18Z")

</div>

> [@YOCKOW](#):
>
> regular expression for a range such as `[A-B]` .

Character class ranges in grapheme-semantic regexes deserves focused discussion. Comparison is [linguistically meaningless](https://forums.swift.org/t/min-function-doesnt-work-on-values-greater-than-9-999-any-idea-why/52004/16) for grapheme clusters. Then again, so is just about [any interpretation](https://github.com/apple/swift-evolution/blob/master/proposals/0221-character-properties.md#detailed-semantics-and-rationale) on `Character`, but that doesn't mean that Swift cannot supply common-sense semantics. We have options as to how we want to define this, and a sensible starting point would be `<` on `Character` itself, noting that `Range<Character>` is uncountable. For the literal, options include warning or erroring out

This isn't anything new, and we will have plenty of [similar concerns](https://forums.swift.org/t/corner-cases-in-character-classification-of-whitespace/12900/18) surrounding our handling of e.g. degenerate grapheme clusters.

> [@YOCKOW](#):
>
> However, at the point of declaration `let regex = /([A-B])/` , it is impossible to determine whether `A` and `B` are `Character` s or `Unicode.Scalar` s.

Right, whether a regex is scalar-semantic or grapheme-semantic may not be know at declaration site, so we may have to invent a way of carrying this information forwards if we want to provide different diagnostics for each.

Also note that many common ranges can be otherwise expressed as a combination of known character classes, so there's some opportunities for nice fixits.

---

_[View the full topic](https://forums.swift.org/t/declarative-string-processing-overview/52459)._
