|
111 | 111 |
|
112 | 112 | # Sub-patterns parts |
113 | 113 | # Whitespace |
114 | | -NEWLINE = r'(?:\r\n|(?!\r\n)[\n\f\r])' |
| 114 | +NEWLINE = r'(?>\r\n|[\n\f\r])' |
115 | 115 | WS = fr'(?:[ \t]|{NEWLINE})' |
116 | 116 | # Comments |
117 | | -COMMENTS = r'(?:/\*(?:[^*]|\*(?!/))*\*/)' |
| 117 | +COMMENTS = r'(?:/\*(?:[^*]|\*(?!/))*+\*/)' |
118 | 118 | # Whitespace with comments included |
119 | 119 | WSC = fr'(?:{WS}|{COMMENTS})' |
120 | 120 | # CSS escapes |
121 | | -CSS_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}{WS}?|[^\r\n\f]|$))' |
122 | | -CSS_STRING_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}{WS}?|{NEWLINE}|[^\r\n\f]|$))' |
| 121 | +CSS_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}+{WS}?+|[^\r\n\f]|$))' |
| 122 | +CSS_STRING_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}+{WS}?+|{NEWLINE}|[^\r\n\f]|$))' |
123 | 123 | # CSS Identifier |
124 | 124 | IDENTIFIER = fr''' |
125 | | -(?:(?:--|-?(?:[^\x00-\x2f\x30-\x40\x5B-\x5E\x60\x7B-\x9f]|{CSS_ESCAPES})) |
126 | | -(?:[^\x00-\x2c\x2e\x2f\x3A-\x40\x5B-\x5E\x60\x7B-\x9f]|{CSS_ESCAPES})*) |
| 125 | +(?:(?:--|-?+(?:[^\x00-\x2f\x30-\x40\x5B-\x5E\x60\x7B-\x9f]|{CSS_ESCAPES})) |
| 126 | +(?:[^\x00-\x2c\x2e\x2f\x3A-\x40\x5B-\x5E\x60\x7B-\x9f]|{CSS_ESCAPES})*+) |
127 | 127 | ''' |
128 | 128 | # `nth` content |
129 | | -NTH = fr'[-+]?(?:[0-9]+n?|n)(?:(?<=n){WSC}*[-+]{WSC}*[0-9]+)?' |
| 129 | +NTH = fr'[-+]?+(?:[0-9]++n?+|n)(?:(?<=n){WSC}*+[-+]{WSC}*+[0-9]++)?+' |
130 | 130 | # Value: quoted string or identifier |
131 | 131 | VALUE = fr''' |
132 | | -(?:"(?:\\(?:{NEWLINE}|[^\r\n\f])|[^\\"\r\n\f])*"| |
133 | | -'(?:\\(?:{NEWLINE}|[^\r\n\f])|[^\\'\r\n\f])*'| |
| 132 | +(?:"(?:\\(?:{NEWLINE}|[^\r\n\f])|[^\\"\r\n\f])*+"| |
| 133 | +'(?:\\(?:{NEWLINE}|[^\r\n\f])|[^\\'\r\n\f])*+'| |
134 | 134 | {IDENTIFIER}) |
135 | 135 | ''' |
136 | 136 | # Attribute value comparison. `!=` is handled special as it is non-standard. |
137 | | -ATTR = fr'(?:{WSC}*(?P<cmp>[!~^|*$]?=){WSC}*(?P<value>{VALUE})(?:{WSC}*(?P<case>[is]))?)?{WSC}*' |
| 137 | +ATTR = fr'(?:{WSC}*+(?P<cmp>[!~^|*$]?+=){WSC}*+(?P<value>{VALUE})(?:{WSC}*+(?P<case>[is]))?+)?+' |
138 | 138 |
|
139 | 139 | # Selector patterns |
140 | 140 | # IDs (`#id`) |
141 | 141 | PAT_ID = fr'\#{IDENTIFIER}' |
142 | 142 | # Classes (`.class`) |
143 | 143 | PAT_CLASS = fr'\.{IDENTIFIER}' |
144 | 144 | # Prefix:Tag (`prefix|tag`) |
145 | | -PAT_TAG = fr'(?P<tag_ns>(?:{IDENTIFIER}|\*)?\|)?(?P<tag_name>{IDENTIFIER}|\*)' |
| 145 | +PAT_TAG = fr'(?P<tag_ns>(?:{IDENTIFIER}|\*)?+\|)?+(?P<tag_name>{IDENTIFIER}|\*)' |
146 | 146 | # Attributes (`[attr]`, `[attr=value]`, etc.) |
147 | | -PAT_ATTR = fr'\[{WSC}*(?P<attr_ns>(?:{IDENTIFIER}|\*)?\|(?!=))?(?P<attr_name>{IDENTIFIER}){ATTR}{WSC}*\]' |
| 147 | +PAT_ATTR = fr'\[{WSC}*+(?P<attr_ns>(?:{IDENTIFIER}|\*)?+\|(?!=))?+(?P<attr_name>{IDENTIFIER}){ATTR}{WSC}*+\]' |
148 | 148 | # Pseudo class (`:pseudo-class`, `:pseudo-class(`) |
149 | | -PAT_PSEUDO_CLASS = fr'(?P<name>:{IDENTIFIER})(?P<open>\({WSC}*)?' |
| 149 | +PAT_PSEUDO_CLASS = fr'(?P<name>:{IDENTIFIER})(?P<open>\({WSC}*+)?+' |
150 | 150 | # Pseudo class special patterns. Matches `:pseudo-class(` for special case pseudo classes. |
151 | | -PAT_PSEUDO_CLASS_SPECIAL = fr'(?P<name>:{IDENTIFIER})(?P<open>\({WSC}*)' |
| 151 | +PAT_PSEUDO_CLASS_SPECIAL = fr'(?P<name>:{IDENTIFIER})(?P<open>\({WSC}*+)' |
152 | 152 | # Custom pseudo class (`:--custom-pseudo`) |
153 | 153 | PAT_PSEUDO_CLASS_CUSTOM = fr'(?P<name>:(?=--){IDENTIFIER})' |
154 | 154 | # Nesting ampersand selector. Matches `&` |
155 | 155 | PAT_AMP = r'&' |
156 | 156 | # Closing pseudo group (`)`) |
157 | | -PAT_PSEUDO_CLOSE = fr'{WSC}*\)' |
| 157 | +PAT_PSEUDO_CLOSE = fr'{WSC}*+\)' |
158 | 158 | # Pseudo element (`::pseudo-element`) |
159 | 159 | PAT_PSEUDO_ELEMENT = fr':{PAT_PSEUDO_CLASS}' |
160 | 160 | # At rule (`@page`, etc.) (not supported) |
161 | 161 | PAT_AT_RULE = fr'@P{IDENTIFIER}' |
162 | 162 | # Pseudo class `nth-child` (`:nth-child(an+b [of S]?)`, `:first-child`, etc.) |
163 | 163 | PAT_PSEUDO_NTH_CHILD = fr''' |
164 | 164 | (?P<pseudo_nth_child>{PAT_PSEUDO_CLASS_SPECIAL} |
165 | | -(?P<nth_child>{NTH}|even|odd))(?:{WSC}*\)|(?P<of>{COMMENTS}*{WS}{WSC}*of{COMMENTS}*{WS}{WSC}*)) |
| 165 | +(?P<nth_child>{NTH}|even|odd))(?:{WSC}*+\)|(?P<of>{COMMENTS}*+{WS}{WSC}*+of{COMMENTS}*+{WS}{WSC}*+)) |
166 | 166 | ''' |
167 | 167 | # Pseudo class `nth-of-type` (`:nth-of-type(an+b)`, `:first-of-type`, etc.) |
168 | 168 | PAT_PSEUDO_NTH_TYPE = fr''' |
169 | 169 | (?P<pseudo_nth_type>{PAT_PSEUDO_CLASS_SPECIAL} |
170 | | -(?P<nth_type>{NTH}|even|odd)){WSC}*\) |
| 170 | +(?P<nth_type>{NTH}|even|odd)){WSC}*+\) |
171 | 171 | ''' |
172 | 172 | # Pseudo class language (`:lang("*-de", en)`) |
173 | | -PAT_PSEUDO_LANG = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<values>{VALUE}(?:{WSC}*,{WSC}*{VALUE})*){WSC}*\)' |
| 173 | +PAT_PSEUDO_LANG = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<values>{VALUE}(?:{WSC}*+,{WSC}*+{VALUE})*+){WSC}*+\)' |
174 | 174 | # Pseudo class direction (`:dir(ltr)`) |
175 | | -PAT_PSEUDO_DIR = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<dir>ltr|rtl){WSC}*\)' |
| 175 | +PAT_PSEUDO_DIR = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<dir>ltr|rtl){WSC}*+\)' |
176 | 176 | # Combining characters (`>`, `~`, ` `, `+`, `,`) |
177 | | -PAT_COMBINE = fr'{COMMENTS}*(?={WS}|[,+>~]){WSC}*(?P<relation>[,+>~])?{WSC}*' |
| 177 | +PAT_COMBINE = fr'{COMMENTS}*+(?={WS}|[,+>~]){WSC}*+(?P<relation>[,+>~])?+{WSC}*+' |
178 | 178 | # Extra: Contains (`:contains(text)`) |
179 | | -PAT_PSEUDO_CONTAINS = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<values>{VALUE}(?:{WSC}*,{WSC}*{VALUE})*){WSC}*\)' |
| 179 | +PAT_PSEUDO_CONTAINS = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<values>{VALUE}(?:{WSC}*+,{WSC}*+{VALUE})*+){WSC}*+\)' |
180 | 180 |
|
181 | 181 | # Regular expressions |
182 | 182 | # CSS escape pattern |
183 | | -RE_CSS_ESC = re.compile(fr'(?:(\\[a-f0-9]{{1,6}}{WSC}?)|(\\[^\r\n\f])|(\\$))', re.I) |
184 | | -RE_CSS_STR_ESC = re.compile(fr'(?:(\\[a-f0-9]{{1,6}}{WS}?)|(\\[^\r\n\f])|(\\$)|(\\{NEWLINE}))', re.I) |
| 183 | +RE_CSS_ESC = re.compile(fr'(?:(\\[a-f0-9]{{1,6}}+{WSC}?+)|(\\[^\r\n\f])|(\\$))', re.I) |
| 184 | +RE_CSS_STR_ESC = re.compile(fr'(?:(\\[a-f0-9]{{1,6}}+{WS}?+)|(\\[^\r\n\f])|(\\$)|(\\{NEWLINE}))', re.I) |
185 | 185 | # Pattern to break up `nth` specifiers |
186 | | -RE_NTH = re.compile(fr'(?P<s1>[-+])?(?P<a>[0-9]+n?|n)(?:(?<=n){WSC}*(?P<s2>[-+]){WSC}*(?P<b>[0-9]+))?', re.I) |
| 186 | +RE_NTH = re.compile(fr'(?P<s1>[-+])?+(?P<a>[0-9]++n?+|n)(?:(?<=n){WSC}*+(?P<s2>[-+]){WSC}*+(?P<b>[0-9]++))?+', re.I) |
187 | 187 | # Pattern to iterate multiple values. |
188 | | -RE_VALUES = re.compile(fr'(?:(?P<value>{VALUE})|(?P<split>{WSC}*,{WSC}*))', re.X) |
| 188 | +RE_VALUES = re.compile(fr'(?:(?P<value>{VALUE})|(?P<split>{WSC}*+,{WSC}*+))', re.X) |
189 | 189 | # Whitespace checks |
190 | 190 | RE_WS = re.compile(WS) |
191 | | -RE_WS_BEGIN = re.compile(fr'^{WSC}*') |
192 | | -RE_WS_END = re.compile(fr'^(?:[ \t]|(?:\n\r|(?!\n\r)[\n\f\r])|{COMMENTS})*') |
| 191 | +RE_WS_BEGIN = re.compile(fr'^{WSC}*+') |
| 192 | +RE_WS_END = re.compile(fr'^(?:[ \t]|(?>\n\r|[\n\f\r])|{COMMENTS})*+') |
193 | 193 | RE_CUSTOM = re.compile(fr'^{PAT_PSEUDO_CLASS_CUSTOM}$', re.X) |
194 | 194 | RE_PSEUDO_CLASS_SPECIAL = re.compile(PAT_PSEUDO_CLASS_SPECIAL, re.I | re.X | re.U) |
195 | 195 | RE_PSEUDO_IGNORE = re.compile(PAT_PSEUDO_CLASS, re.X | re.I | re.U) |
|
0 commit comments