Skip to content

Commit 925f51b

Browse files
committed
Add parser support for \p{L&}
This is a PCRE spelling for a cased letter.
1 parent 13342eb commit 925f51b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Sources/_RegexParser/Regex/Parse/CharacterPropertyClassification.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ extension Source {
3232
static private func classifyGeneralCategory(
3333
_ str: String
3434
) -> Unicode.ExtendedGeneralCategory? {
35-
// This uses the aliases defined in
36-
// https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt.
35+
// This uses the aliases defined in https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt.
36+
// Additionally, uses the `L& = Lc` alias defined by PCRE.
3737
withNormalizedForms(str) { str in
3838
switch str {
3939
case "c", "other": return .other
@@ -43,7 +43,7 @@ extension Source {
4343
case "co", "privateuse": return .privateUse
4444
case "cs", "surrogate": return .surrogate
4545
case "l", "letter": return .letter
46-
case "lc", "casedletter": return .casedLetter
46+
case "lc", "l&", "casedletter": return .casedLetter
4747
case "ll", "lowercaseletter": return .lowercaseLetter
4848
case "lm", "modifierletter": return .modifierLetter
4949
case "lo", "otherletter": return .otherLetter

Tests/RegexTests/MatchTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ extension RegexTests {
698698
firstMatchTest(#"\p{L}"#, input: "\u{0374}\u{00AA}123abcXYZ", match: "\u{0374}")
699699
firstMatchTest(#"\p{Lc}"#, input: "\u{0374}\u{00AA}123abcXYZ", match: "a")
700700
firstMatchTest(#"\p{Lc}"#, input: "\u{0374}\u{00AA}123XYZ", match: "X")
701+
firstMatchTest(#"\p{L&}"#, input: "\u{0374}\u{00AA}123abcXYZ", match: "a")
702+
firstMatchTest(#"\p{L&}"#, input: "\u{0374}\u{00AA}123XYZ", match: "X")
701703

702704
firstMatchTest(
703705
#"\P{Cc}"#, input: "\n\n\nXYZ", match: "X")

Tests/RegexTests/ParseTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,9 @@ extension RegexTests {
11561156
#"\p{C}+"#,
11571157
oneOrMore(of: prop(.generalCategory(.other))))
11581158

1159+
// L& defined by PCRE.
1160+
parseTest(#"\p{L&}"#, prop(.generalCategory(.casedLetter)))
1161+
11591162
// UAX44-LM3 means all of the below are equivalent.
11601163
let lowercaseLetter = prop(.generalCategory(.lowercaseLetter))
11611164
parseTest(#"\p{ll}"#, lowercaseLetter)

0 commit comments

Comments
 (0)