1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! §22.2.1's `\p{…}` — which sets of code points a pattern may name, and what they contain.
//!
//! The data is in [`crate::unicode_property_table`], which is generated; everything that decides
//! what a *name* means is here, and so is every test.
//!
//! # Two forms and no third
//!
//! `\p{Lu}` is a lone name, which §22.2.1 resolves against the binary properties **and** the
//! `General_Category` values — one namespace searched twice, not two spellings of one thing.
//! `\p{Script=Greek}` is a name and a value, and only three names take one: `General_Category`,
//! `Script` and `Script_Extensions`. Anything else is a Syntax Error, including a name that is a
//! real Unicode property but not one of those three: `\p{Age=9.0}` is invalid JavaScript however
//! meaningful it is to Unicode.
//!
//! # Why the names are matched exactly
//!
//! The specification's tables are of *exact* strings — `Lu`, `Uppercase_Letter` — and neither
//! case-folds nor ignores the underscores, where UTS #18 suggests an implementation may. So
//! `\p{uppercase_letter}` is a Syntax Error and `\p{Uppercase_Letter}` is not, and a lookup that
//! normalised first would accept a whole family of patterns no other engine does.
use crate;
/// A set of code points a `\p{…}` names, and whether the escape was the negated `\P{…}`.
///
/// The ranges are `'static` and shared with every other pattern naming the same property: a set is
/// a slice into the generated table rather than something a compiled pattern owns. That is what
/// makes `\p{Alphabetic}` free to write — the 1,400 ranges behind it are in the binary once.
/// §22.2.1's *properties of strings* — the `v`-flag names that match sequences, not code points.
///
/// Listed rather than resolved because ViperJS does not have them: `\p{RGI_Emoji}` matches a
/// *string* of several code points, which the matcher here has no shape for. Naming them keeps the
/// refusal honest — they are a feature this engine lacks, not a name the specification rejects,
/// and only the first of those may be judged as an early error.
pub const OF_STRINGS: & = &;
/// Resolve what was written between the braces — `None` if it names nothing §22.2.1 allows.
///
/// The caller has already read the braces and decided the escape is `\p` rather than `\P`; this is
/// only about the name. A `None` is a Syntax Error at the call site and not an empty set: a
/// pattern naming a property that does not exist is not a pattern that matches nothing.
/// A linear scan of one table, matching the spelling exactly.
///
/// Linear rather than sorted-and-searched because it happens when a pattern is **compiled** and
/// never while one runs, and the longest table is a few hundred entries. A binary search would
/// need the generated table to be sorted by name, which is a property nothing else wants and one
/// more thing a regeneration could quietly get wrong.
],
name: &str,
)