Declarative String Processing Overview

I wonder how to precompile a regular expression for a range such as [A-B].

Given a character "A\u{20DD}"(LATIN CAPITAL LETTER A + COMBINING ENCLOSING CIRCLE).

print(Character("A\u{20DD}") > Character("A")) // -> true
print(Character("A\u{20DD}") < Character("B") ) // -> true

let regex = /([A-B])/

switch "A\u{20DD}" {
case let something <- regex:
  // What is the type of `something`?
}
  • something would be Character("A\u{20DD}") when applied with grapheme-cluster semantics.
  • something would be Unicode.Scalar("A") when applied with scalar semantics.

However, at the point of declaration let regex = /([A-B])/, it is impossible to determine whether A and B are Characters or Unicode.Scalars.

2 Likes