Debian Codegraph @

src/3rdparty/javascriptcore/JavaScriptCore/yarr/RegexParser.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef RegexParser_h
27 #define RegexParser_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/yarr/RegexParser.h:27:9`!
28
29 #include <wtf/Platform.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h`/
30
31 #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(YARR)
32
33 #include <UString.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h`/
34 #include <wtf/ASCIICType.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/ASCIICType.h`/
35 #include <wtf/unicode/Unicode.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/unicode/Unicode.h`/
36 #include <limits.h>
37
38 namespace JSCcxx . . $ QTJSC/ { namespace Yarrcxx . . $ QTJSC/Yarr/ {
39
40 enum BuiltInCharacterClassIDcxx . . $ QTJSC/Yarr/BuiltInCharacterClassID# {
41 DigitClassIDcxx . . $ QTJSC/Yarr/DigitClassID.,
42 SpaceClassIDcxx . . $ QTJSC/Yarr/SpaceClassID.,
43 WordClassIDcxx . . $ QTJSC/Yarr/WordClassID.,
44 NewlineClassIDcxx . . $ QTJSC/Yarr/NewlineClassID.,
45 };
46
47 // The Parser class should not be used directly - only via the Yarr::parse() method.
48 template<class Delegate>
49 class Parsercxx . . $ QTJSC/Yarr/Parser# {
50 private:
51 template<class FriendDelegate>
52 friend const char* parsecxx . . $ QTJSC/Yarr/parse(fe7b6006fc98a375).(FriendDelegate& delegate, const UStringcxx . . $ QTJSC/UString#& pattern, unsigned backReferenceLimit);
53
54 enum ErrorCodecxx . . $ QTJSC/Yarr/Parser#ErrorCode# {
55 NoErrorcxx . . $ QTJSC/Yarr/Parser#NoError.,
56 PatternTooLargecxx . . $ QTJSC/Yarr/Parser#PatternTooLarge.,
57 QuantifierOutOfOrdercxx . . $ QTJSC/Yarr/Parser#QuantifierOutOfOrder.,
58 QuantifierWithoutAtomcxx . . $ QTJSC/Yarr/Parser#QuantifierWithoutAtom.,
59 MissingParenthesescxx . . $ QTJSC/Yarr/Parser#MissingParentheses.,
60 ParenthesesUnmatchedcxx . . $ QTJSC/Yarr/Parser#ParenthesesUnmatched.,
61 ParenthesesTypeInvalidcxx . . $ QTJSC/Yarr/Parser#ParenthesesTypeInvalid.,
62 CharacterClassUnmatchedcxx . . $ QTJSC/Yarr/Parser#CharacterClassUnmatched.,
63 CharacterClassOutOfOrdercxx . . $ QTJSC/Yarr/Parser#CharacterClassOutOfOrder.,
64 EscapeUnterminatedcxx . . $ QTJSC/Yarr/Parser#EscapeUnterminated.,
65 NumberOfErrorCodescxx . . $ QTJSC/Yarr/Parser#NumberOfErrorCodes.
66 };
67
68 /*
69 * CharacterClassParserDelegate:
70 *
71 * The class CharacterClassParserDelegate is used in the parsing of character
72 * classes. This class handles detection of character ranges. This class
73 * implements enough of the delegate interface such that it can be passed to
74 * parseEscape() as an EscapeDelegate. This allows parseEscape() to be reused
75 * to perform the parsing of escape characters in character sets.
76 */
77 class CharacterClassParserDelegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate# {
78 public:
79 CharacterClassParserDelegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#CharacterClassParserDelegate(7c134ea2f688fb69).(Delegate& delegate, ErrorCodecxx . . $ QTJSC/Yarr/Parser#ErrorCode#& err)
80 : m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate.(delegate)
81 , m_errcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_err.(err)
82 , m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state.(emptycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#empty.)
83 {
84 }
85
86 /*
87 * begin():
88 *
89 * Called at beginning of construction.
90 */
91 void begincxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#begin(b45ddcbc8423892c).(bool invert)
92 {
93 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassBegin(invert);
94 }
95
96 /*
97 * atomPatternCharacterUnescaped():
98 *
99 * This method is called directly from parseCharacterClass(), to report a new
100 * pattern character token. This method differs from atomPatternCharacter(),
101 * which will be called from parseEscape(), since a hypen provided via this
102 * method may be indicating a character range, but a hyphen parsed by
103 * parseEscape() cannot be interpreted as doing so.
104 */
105 void atomPatternCharacterUnescapedcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#atomPatternCharacterUnescaped(ed53e3bbd3fa2f69).(UCharcxx . . $ UChar# ch)
106 {
107 switch (m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state.) {
108 case emptycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#empty.:
109 m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character. = ch;
110 m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. = cachedCharactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacter.;
111 break;
112
113 case cachedCharactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacter.:
114 if (ch == '-')
115 m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. = cachedCharacterHyphencxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacterHyphen.;
116 else {
117 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassAtom(m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character.);
118 m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character. = ch;
119 }
120 break;
121
122 case cachedCharacterHyphencxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacterHyphen.:
123 if (ch >= m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character.)
124 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassRange(m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character., ch);
125 else
126 m_errcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_err. = CharacterClassOutOfOrdercxx . . $ QTJSC/Yarr/Parser#CharacterClassOutOfOrder.;
127 m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. = emptycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#empty.;
128 }
129 }
130
131 /*
132 * atomPatternCharacter():
133 *
134 * Adds a pattern character, called by parseEscape(), as such will not
135 * interpret a hyphen as indicating a character range.
136 */
137 void atomPatternCharactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#atomPatternCharacter(ed53e3bbd3fa2f69).(UCharcxx . . $ UChar# ch)
138 {
139 // Flush if a character is already pending to prevent the
140 // hyphen from begin interpreted as indicating a range.
141 if((ch == '-') && (m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. ==cxx . . $ QTJSC/`operator==`(5e10d8f38fa82016). cachedCharactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacter.))
142 flushcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#flush(49f6e7a06ebc5aa8).();
143
144 atomPatternCharacterUnescapedcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#atomPatternCharacterUnescaped(ed53e3bbd3fa2f69).(ch);
145 }
146
147 /*
148 * atomBuiltInCharacterClass():
149 *
150 * Adds a built-in character class, called by parseEscape().
151 */
152 void atomBuiltInCharacterClasscxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#atomBuiltInCharacterClass(a31f650bd0823a02).(BuiltInCharacterClassIDcxx . . $ QTJSC/Yarr/BuiltInCharacterClassID# classID, bool invert)
153 {
154 flushcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#flush(49f6e7a06ebc5aa8).();
155 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassBuiltIn(classID, invert);
156 }
157
158 /*
159 * end():
160 *
161 * Called at end of construction.
162 */
163 void endcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#end(49f6e7a06ebc5aa8).()
164 {
165 flushcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#flush(49f6e7a06ebc5aa8).();
166 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassEnd();
167 }
168
169 // parseEscape() should never call these delegate methods when
170 // invoked with inCharacterClass set.
171 void assertionWordBoundarycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#assertionWordBoundary(b45ddcbc8423892c).(bool) { ASSERT_NOT_REACHEDcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:185:9`!(); }
172 void atomBackReferencecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#atomBackReference(cb2f890c2fdad230).(unsigned) { ASSERT_NOT_REACHEDcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:185:9`!(); }
173
174 private:
175 void flushcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#flush(49f6e7a06ebc5aa8).()
176 {
177 if (m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. !=cxx . . $ QTJSC/`operator!=`(c411ccca4fa1792). emptycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#empty.) // either cachedCharacter or cachedCharacterHyphen
178 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassAtom(m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character.);
179 if (m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. ==cxx . . $ QTJSC/`operator==`(c411ccca4fa1792). cachedCharacterHyphencxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacterHyphen.)
180 m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate..atomCharacterClassAtom('-');
181 m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state. = emptycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#empty.;
182 }
183
184 Delegate& m_delegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_delegate.;
185 ErrorCodecxx . . $ QTJSC/Yarr/Parser#ErrorCode#& m_errcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_err.;
186 enum CharacterClassConstructionStatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#CharacterClassConstructionState# {
187 emptycxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#empty.,
188 cachedCharactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacter.,
189 cachedCharacterHyphencxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#cachedCharacterHyphen.,
190 } m_statecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_state.;
191 UCharcxx . . $ UChar# m_charactercxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#m_character.;
192 };
193
194 Parsercxx . . $ QTJSC/Yarr/Parser#`Parser<Delegate>`(338a133a82ebfee3).(Delegate& delegate, const UStringcxx . . $ QTJSC/UString#& pattern, unsigned backReferenceLimit)
195 : m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate.(delegate)
196 , m_backReferenceLimitcxx . . $ QTJSC/Yarr/Parser#m_backReferenceLimit.(backReferenceLimit)
197 , m_errcxx . . $ QTJSC/Yarr/Parser#m_err.(NoErrorcxx . . $ QTJSC/Yarr/Parser#NoError.)
198 , m_datacxx . . $ QTJSC/Yarr/Parser#m_data.(pattern.datacxx . . $ QTJSC/UString#data(9865edf6270d80f8).())
199 , m_sizecxx . . $ QTJSC/Yarr/Parser#m_size.(pattern.sizecxx . . $ QTJSC/UString#size(455f465bc33b4cdf).())
200 , m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.(0)
201 , m_parenthesesNestingDepthcxx . . $ QTJSC/Yarr/Parser#m_parenthesesNestingDepth.(0)
202 {
203 }
204
205 /*
206 * parseEscape():
207 *
208 * Helper for parseTokens() AND parseCharacterClass().
209 * Unlike the other parser methods, this function does not report tokens
210 * directly to the member delegate (m_delegate), instead tokens are
211 * emitted to the delegate provided as an argument. In the case of atom
212 * escapes, parseTokens() will call parseEscape() passing m_delegate as
213 * an argument, and as such the escape will be reported to the delegate.
214 *
215 * However this method may also be used by parseCharacterClass(), in which
216 * case a CharacterClassParserDelegate will be passed as the delegate that
217 * tokens should be added to. A boolean flag is also provided to indicate
218 * whether that an escape in a CharacterClass is being parsed (some parsing
219 * rules change in this context).
220 *
221 * The boolean value returned by this method indicates whether the token
222 * parsed was an atom (outside of a characted class \b and \B will be
223 * interpreted as assertions).
224 */
225 template<bool inCharacterClass, class EscapeDelegate>
226 bool parseEscapecxx . . $ QTJSC/Yarr/Parser#parseEscape(1418bae7cebc6a27).(EscapeDelegate& delegate)
227 {
228 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_err);
229 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(peek() == '\\');
230 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
231
232 if (atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).()) {
233 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = EscapeUnterminatedcxx . . $ QTJSC/Yarr/Parser#EscapeUnterminated.;
234 return false;
235 }
236
237 switch (peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).()) {
238 // Assertions
239 case 'b':
240 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
241 if (inCharacterClass)
242 delegate.atomPatternCharacter('\b');
243 else {
244 delegate.assertionWordBoundary(false);
245 return false;
246 }
247 break;
248 case 'B':
249 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
250 if (inCharacterClass)
251 delegate.atomPatternCharacter('B');
252 else {
253 delegate.assertionWordBoundary(true);
254 return false;
255 }
256 break;
257
258 // CharacterClassEscape
259 case 'd':
260 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
261 delegate.atomBuiltInCharacterClass(DigitClassIDcxx . . $ QTJSC/Yarr/DigitClassID., false);
262 break;
263 case 's':
264 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
265 delegate.atomBuiltInCharacterClass(SpaceClassIDcxx . . $ QTJSC/Yarr/SpaceClassID., false);
266 break;
267 case 'w':
268 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
269 delegate.atomBuiltInCharacterClass(WordClassIDcxx . . $ QTJSC/Yarr/WordClassID., false);
270 break;
271 case 'D':
272 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
273 delegate.atomBuiltInCharacterClass(DigitClassIDcxx . . $ QTJSC/Yarr/DigitClassID., true);
274 break;
275 case 'S':
276 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
277 delegate.atomBuiltInCharacterClass(SpaceClassIDcxx . . $ QTJSC/Yarr/SpaceClassID., true);
278 break;
279 case 'W':
280 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
281 delegate.atomBuiltInCharacterClass(WordClassIDcxx . . $ QTJSC/Yarr/WordClassID., true);
282 break;
283
284 // DecimalEscape
285 case '1':
286 case '2':
287 case '3':
288 case '4':
289 case '5':
290 case '6':
291 case '7':
292 case '8':
293 case '9': {
294 // To match Firefox, we parse an invalid backreference in the range [1-7] as an octal escape.
295 // First, try to parse this as backreference.
296 if (!inCharacterClass) {
297 ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState# state = saveStatecxx . . $ QTJSC/Yarr/Parser#saveState(db52760e79bf9054).();
298
299 unsigned backReference = consumeNumbercxx . . $ QTJSC/Yarr/Parser#consumeNumber(db52760e79bf9054).();
300 if (backReference <= m_backReferenceLimitcxx . . $ QTJSC/Yarr/Parser#m_backReferenceLimit.) {
301 delegate.atomBackReference(backReference);
302 break;
303 }
304
305 restoreStatecxx . . $ QTJSC/Yarr/Parser#restoreState(cb2f890c2fdad230).(state);
306 }
307
308 // Not a backreference, and not octal.
309 if (peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).() >=cxx . . $ `operator>=`(9835b8dbb8c249ee). '8') {
310 delegate.atomPatternCharacter('\\');
311 break;
312 }
313
314 // Fall-through to handle this as an octal escape.
315 }
316
317 // Octal escape
318 case '0':
319 delegate.atomPatternCharacter(consumeOctalcxx . . $ QTJSC/Yarr/Parser#consumeOctal(db52760e79bf9054).());
320 break;
321
322 // ControlEscape
323 case 'f':
324 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
325 delegate.atomPatternCharacter('\f');
326 break;
327 case 'n':
328 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
329 delegate.atomPatternCharacter('\n');
330 break;
331 case 'r':
332 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
333 delegate.atomPatternCharacter('\r');
334 break;
335 case 't':
336 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
337 delegate.atomPatternCharacter('\t');
338 break;
339 case 'v':
340 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
341 delegate.atomPatternCharacter('\v');
342 break;
343
344 // ControlLetter
345 case 'c': {
346 ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState# state = saveStatecxx . . $ QTJSC/Yarr/Parser#saveState(db52760e79bf9054).();
347 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
348 if (!atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).()) {
349 int control = consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
350
351 // To match Firefox, inside a character class, we also accept numbers and '_' as control characters.
352 if (inCharacterClass ? WTFcxx . . $ QTWTF/::isASCIIAlphanumericcxx . . $ QTWTF/isASCIIAlphanumeric(83c267b20bac841a).(control) || (control == '_') : WTFcxx . . $ QTWTF/::isASCIIAlphacxx . . $ QTWTF/isASCIIAlpha(83c267b20bac841a).(control)) {
353 delegate.atomPatternCharacter(control & 0x1f);
354 break;
355 }
356 }
357 restoreStatecxx . . $ QTJSC/Yarr/Parser#restoreState(cb2f890c2fdad230).(state);
358 delegate.atomPatternCharacter('\\');
359 break;
360 }
361
362 // HexEscape
363 case 'x': {
364 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
365 int x = tryConsumeHexcxx . . $ QTJSC/Yarr/Parser#tryConsumeHex(7864480464b09eea).(2);
366 if (x == -1)
367 delegate.atomPatternCharacter('x');
368 else
369 delegate.atomPatternCharacter(x);
370 break;
371 }
372
373 // UnicodeEscape
374 case 'u': {
375 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
376 int u = tryConsumeHexcxx . . $ QTJSC/Yarr/Parser#tryConsumeHex(7864480464b09eea).(4);
377 if (u == -1)
378 delegate.atomPatternCharacter('u');
379 else
380 delegate.atomPatternCharacter(u);
381 break;
382 }
383
384 // IdentityEscape
385 default:
386 delegate.atomPatternCharacter(consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).());
387 }
388
389 return true;
390 }
391
392 /*
393 * parseAtomEscape(), parseCharacterClassEscape():
394 *
395 * These methods alias to parseEscape().
396 */
397 bool parseAtomEscapecxx . . $ QTJSC/Yarr/Parser#parseAtomEscape(c9857a73d68e59ba).()
398 {
399 return parseEscapecxx . . $ QTJSC/Yarr/Parser#parseEscape(1418bae7cebc6a27).<false>(m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate.);
400 }
401 void parseCharacterClassEscapecxx . . $ QTJSC/Yarr/Parser#parseCharacterClassEscape(c9be8f753a7525a7).(CharacterClassParserDelegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#& delegate)
402 {
403 parseEscapecxx . . $ QTJSC/Yarr/Parser#parseEscape(1418bae7cebc6a27).<true>(delegate);
404 }
405
406 /*
407 * parseCharacterClass():
408 *
409 * Helper for parseTokens(); calls dirctly and indirectly (via parseCharacterClassEscape)
410 * to an instance of CharacterClassParserDelegate, to describe the character class to the
411 * delegate.
412 */
413 void parseCharacterClasscxx . . $ QTJSC/Yarr/Parser#parseCharacterClass(49f6e7a06ebc5aa8).()
414 {
415 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_err);
416 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(peek() == '[');
417 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
418
419 CharacterClassParserDelegatecxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate# characterClassConstructor(m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate., m_errcxx . . $ QTJSC/Yarr/Parser#m_err.);
420
421 characterClassConstructor.begincxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#begin(b45ddcbc8423892c).(tryConsumecxx . . $ QTJSC/Yarr/Parser#tryConsume(3c978dac0e5ee2ad).('^'));
422
423 while (!atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).()) {
424 switch (peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).()) {
425 case ']':
426 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
427 characterClassConstructor.endcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#end(49f6e7a06ebc5aa8).();
428 return;
429
430 case '\\':
431 parseCharacterClassEscapecxx . . $ QTJSC/Yarr/Parser#parseCharacterClassEscape(c9be8f753a7525a7).(characterClassConstructor);
432 break;
433
434 default:
435 characterClassConstructor.atomPatternCharacterUnescapedcxx . . $ QTJSC/Yarr/Parser#CharacterClassParserDelegate#atomPatternCharacterUnescaped(ed53e3bbd3fa2f69).(consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).());
436 }
437
438 if (m_errcxx . . $ QTJSC/Yarr/Parser#m_err.)
439 return;
440 }
441
442 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = CharacterClassUnmatchedcxx . . $ QTJSC/Yarr/Parser#CharacterClassUnmatched.;
443 }
444
445 /*
446 * parseParenthesesBegin():
447 *
448 * Helper for parseTokens(); checks for parentheses types other than regular capturing subpatterns.
449 */
450 void parseParenthesesBegincxx . . $ QTJSC/Yarr/Parser#parseParenthesesBegin(49f6e7a06ebc5aa8).()
451 {
452 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_err);
453 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(peek() == '(');
454 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
455
456 if (tryConsumecxx . . $ QTJSC/Yarr/Parser#tryConsume(3c978dac0e5ee2ad).('?')) {
457 if (atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).()) {
458 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = ParenthesesTypeInvalidcxx . . $ QTJSC/Yarr/Parser#ParenthesesTypeInvalid.;
459 return;
460 }
461
462 switch (consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).()) {
463 case ':':
464 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomParenthesesSubpatternBegin(false);
465 break;
466
467 case '=':
468 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomParentheticalAssertionBegin();
469 break;
470
471 case '!':
472 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomParentheticalAssertionBegin(true);
473 break;
474
475 default:
476 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = ParenthesesTypeInvalidcxx . . $ QTJSC/Yarr/Parser#ParenthesesTypeInvalid.;
477 }
478 } else
479 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomParenthesesSubpatternBegin();
480
481 ++m_parenthesesNestingDepthcxx . . $ QTJSC/Yarr/Parser#m_parenthesesNestingDepth.;
482 }
483
484 /*
485 * parseParenthesesEnd():
486 *
487 * Helper for parseTokens(); checks for parse errors (due to unmatched parentheses).
488 */
489 void parseParenthesesEndcxx . . $ QTJSC/Yarr/Parser#parseParenthesesEnd(49f6e7a06ebc5aa8).()
490 {
491 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_err);
492 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(peek() == ')');
493 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
494
495 if (m_parenthesesNestingDepthcxx . . $ QTJSC/Yarr/Parser#m_parenthesesNestingDepth. > 0)
496 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomParenthesesEnd();
497 else
498 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = ParenthesesUnmatchedcxx . . $ QTJSC/Yarr/Parser#ParenthesesUnmatched.;
499
500 --m_parenthesesNestingDepthcxx . . $ QTJSC/Yarr/Parser#m_parenthesesNestingDepth.;
501 }
502
503 /*
504 * parseQuantifier():
505 *
506 * Helper for parseTokens(); checks for parse errors and non-greedy quantifiers.
507 */
508 void parseQuantifiercxx . . $ QTJSC/Yarr/Parser#parseQuantifier(459becc0a76c23b8).(bool lastTokenWasAnAtom, unsigned min, unsigned max)
509 {
510 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_err);
511 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(min <= max);
512
513 if (lastTokenWasAnAtom)
514 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..quantifyAtom(min, max, !tryConsumecxx . . $ QTJSC/Yarr/Parser#tryConsume(3c978dac0e5ee2ad).('?'));
515 else
516 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = QuantifierWithoutAtomcxx . . $ QTJSC/Yarr/Parser#QuantifierWithoutAtom.;
517 }
518
519 /*
520 * parseTokens():
521 *
522 * This method loops over the input pattern reporting tokens to the delegate.
523 * The method returns when a parse error is detected, or the end of the pattern
524 * is reached. One piece of state is tracked around the loop, which is whether
525 * the last token passed to the delegate was an atom (this is necessary to detect
526 * a parse error when a quantifier provided without an atom to quantify).
527 */
528 void parseTokenscxx . . $ QTJSC/Yarr/Parser#parseTokens(49f6e7a06ebc5aa8).()
529 {
530 bool lastTokenWasAnAtom = false;
531
532 while (!atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).()) {
533 switch (peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).()) {
534 case '|':
535 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
536 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..disjunction();
537 lastTokenWasAnAtom = false;
538 break;
539
540 case '(':
541 parseParenthesesBegincxx . . $ QTJSC/Yarr/Parser#parseParenthesesBegin(49f6e7a06ebc5aa8).();
542 lastTokenWasAnAtom = false;
543 break;
544
545 case ')':
546 parseParenthesesEndcxx . . $ QTJSC/Yarr/Parser#parseParenthesesEnd(49f6e7a06ebc5aa8).();
547 lastTokenWasAnAtom = true;
548 break;
549
550 case '^':
551 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
552 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..assertionBOL();
553 lastTokenWasAnAtom = false;
554 break;
555
556 case '$':
557 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
558 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..assertionEOL();
559 lastTokenWasAnAtom = false;
560 break;
561
562 case '.':
563 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
564 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomBuiltInCharacterClass(NewlineClassIDcxx . . $ QTJSC/Yarr/NewlineClassID., true);
565 lastTokenWasAnAtom = true;
566 break;
567
568 case '[':
569 parseCharacterClasscxx . . $ QTJSC/Yarr/Parser#parseCharacterClass(49f6e7a06ebc5aa8).();
570 lastTokenWasAnAtom = true;
571 break;
572
573 case '\\':
574 lastTokenWasAnAtom = parseAtomEscapecxx . . $ QTJSC/Yarr/Parser#parseAtomEscape(c9857a73d68e59ba).();
575 break;
576
577 case '*':
578 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
579 parseQuantifiercxx . . $ QTJSC/Yarr/Parser#parseQuantifier(459becc0a76c23b8).(lastTokenWasAnAtom, 0, UINT_MAXcxx . . $ `<external>/67164224788392828/limits.h:124:9`!);
580 lastTokenWasAnAtom = false;
581 break;
582
583 case '+':
584 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
585 parseQuantifiercxx . . $ QTJSC/Yarr/Parser#parseQuantifier(459becc0a76c23b8).(lastTokenWasAnAtom, 1, UINT_MAXcxx . . $ `<external>/67164224788392828/limits.h:124:9`!);
586 lastTokenWasAnAtom = false;
587 break;
588
589 case '?':
590 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
591 parseQuantifiercxx . . $ QTJSC/Yarr/Parser#parseQuantifier(459becc0a76c23b8).(lastTokenWasAnAtom, 0, 1);
592 lastTokenWasAnAtom = false;
593 break;
594
595 case '{': {
596 ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState# state = saveStatecxx . . $ QTJSC/Yarr/Parser#saveState(db52760e79bf9054).();
597
598 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
599 if (peekIsDigitcxx . . $ QTJSC/Yarr/Parser#peekIsDigit(c9857a73d68e59ba).()) {
600 unsigned min = consumeNumbercxx . . $ QTJSC/Yarr/Parser#consumeNumber(db52760e79bf9054).();
601 unsigned max = min;
602
603 if (tryConsumecxx . . $ QTJSC/Yarr/Parser#tryConsume(3c978dac0e5ee2ad).(','))
604 max = peekIsDigitcxx . . $ QTJSC/Yarr/Parser#peekIsDigit(c9857a73d68e59ba).() ? consumeNumbercxx . . $ QTJSC/Yarr/Parser#consumeNumber(db52760e79bf9054).() : UINT_MAXcxx . . $ `<external>/67164224788392828/limits.h:124:9`!;
605
606 if (tryConsumecxx . . $ QTJSC/Yarr/Parser#tryConsume(3c978dac0e5ee2ad).('}')) {
607 if (min <= max)
608 parseQuantifiercxx . . $ QTJSC/Yarr/Parser#parseQuantifier(459becc0a76c23b8).(lastTokenWasAnAtom, min, max);
609 else
610 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = QuantifierOutOfOrdercxx . . $ QTJSC/Yarr/Parser#QuantifierOutOfOrder.;
611 lastTokenWasAnAtom = false;
612 break;
613 }
614 }
615
616 restoreStatecxx . . $ QTJSC/Yarr/Parser#restoreState(cb2f890c2fdad230).(state);
617 } // if we did not find a complete quantifer, fall through to the default case.
618
619 default:
620 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..atomPatternCharacter(consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).());
621 lastTokenWasAnAtom = true;
622 }
623
624 if (m_errcxx . . $ QTJSC/Yarr/Parser#m_err.)
625 return;
626 }
627
628 if (m_parenthesesNestingDepthcxx . . $ QTJSC/Yarr/Parser#m_parenthesesNestingDepth. > 0)
629 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = MissingParenthesescxx . . $ QTJSC/Yarr/Parser#MissingParentheses.;
630 }
631
632 /*
633 * parse():
634 *
635 * This method calls regexBegin(), calls parseTokens() to parse over the input
636 * patterns, calls regexEnd() or regexError() as appropriate, and converts any
637 * error code to a const char* for a result.
638 */
639 const char* parsecxx . . $ QTJSC/Yarr/Parser#parse(33a1f659e94feb42).()
640 {
641 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..regexBegin();
642
643 if (m_sizecxx . . $ QTJSC/Yarr/Parser#m_size. > MAX_PATTERN_SIZEcxx . . $ QTJSC/Yarr/Parser#MAX_PATTERN_SIZE.)
644 m_errcxx . . $ QTJSC/Yarr/Parser#m_err. = PatternTooLargecxx . . $ QTJSC/Yarr/Parser#PatternTooLarge.;
645 else
646 parseTokenscxx . . $ QTJSC/Yarr/Parser#parseTokens(49f6e7a06ebc5aa8).();
647 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(atEndOfPattern() || m_err);
648
649 if (m_errcxx . . $ QTJSC/Yarr/Parser#m_err.)
650 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..regexError();
651 else
652 m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate..regexEnd();
653
654 // The order of this array must match the ErrorCode enum.
655 static const char* errorMessages[NumberOfErrorCodescxx . . $ QTJSC/Yarr/Parser#NumberOfErrorCodes.] = {
656 0, // NoError
657 "regular expression too large",
658 "numbers out of order in {} quantifier",
659 "nothing to repeat",
660 "missing )",
661 "unmatched parentheses",
662 "unrecognized character after (?",
663 "missing terminating ] for character class",
664 "range out of order in character class",
665 "\\ at end of pattern"
666 };
667
668 return errorMessages[m_errcxx . . $ QTJSC/Yarr/Parser#m_err.];
669 }
670
671
672 // Misc helper functions:
673
674 typedef unsigned ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState#;
675
676 ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState# saveStatecxx . . $ QTJSC/Yarr/Parser#saveState(db52760e79bf9054).()
677 {
678 return m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.;
679 }
680
681 void restoreStatecxx . . $ QTJSC/Yarr/Parser#restoreState(cb2f890c2fdad230).(ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState# state)
682 {
683 m_indexcxx . . $ QTJSC/Yarr/Parser#m_index. = state;
684 }
685
686 bool atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).()
687 {
688 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(m_index <= m_size);
689 return m_indexcxx . . $ QTJSC/Yarr/Parser#m_index. == m_sizecxx . . $ QTJSC/Yarr/Parser#m_size.;
690 }
691
692 int peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).()
693 {
694 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(m_index < m_size);
695 return m_datacxx . . $ QTJSC/Yarr/Parser#m_data.[m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.];
696 }
697
698 bool peekIsDigitcxx . . $ QTJSC/Yarr/Parser#peekIsDigit(c9857a73d68e59ba).()
699 {
700 return !atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).() && WTFcxx . . $ `<built-in>:467:9`!::isASCIIDigitcxx . . $ QTWTF/isASCIIDigit(d277392ef19a3282).(peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).());
701 }
702
703 unsigned peekDigitcxx . . $ QTJSC/Yarr/Parser#peekDigit(db52760e79bf9054).()
704 {
705 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(peekIsDigit());
706 return peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).() - '0';
707 }
708
709 int consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).()
710 {
711 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(m_index < m_size);
712 return m_datacxx . . $ QTJSC/Yarr/Parser#m_data.[m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.++];
713 }
714
715 unsigned consumeDigitcxx . . $ QTJSC/Yarr/Parser#consumeDigit(db52760e79bf9054).()
716 {
717 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(peekIsDigit());
718 return consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).() - '0';
719 }
720
721 unsigned consumeNumbercxx . . $ QTJSC/Yarr/Parser#consumeNumber(db52760e79bf9054).()
722 {
723 unsigned n = consumeDigitcxx . . $ QTJSC/Yarr/Parser#consumeDigit(db52760e79bf9054).();
724 // check for overflow.
725 for (unsigned newValue; peekIsDigitcxx . . $ QTJSC/Yarr/Parser#peekIsDigit(c9857a73d68e59ba).() && ((newValue = n * 10 +cxx . . $ operator+(f3789794639247d3). peekDigitcxx . . $ QTJSC/Yarr/Parser#peekDigit(db52760e79bf9054).()) >=cxx . . $ `operator>=`(9835b8dbb8c249ee). n); ) {
726 n = newValue;
727 consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).();
728 }
729 return n;
730 }
731
732 unsigned consumeOctalcxx . . $ QTJSC/Yarr/Parser#consumeOctal(db52760e79bf9054).()
733 {
734 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(WTF::isASCIIOctalDigit(peek()));
735
736 unsigned n = consumeDigitcxx . . $ QTJSC/Yarr/Parser#consumeDigit(db52760e79bf9054).();
737 while (n < 32 && !atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).() && WTFcxx . . $ QTWTF/::isASCIIOctalDigitcxx . . $ QTWTF/isASCIIOctalDigit(b5fd09639b7a0261).(peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).()))
738 n = n * 8 +cxx . . $ operator+(f3789794639247d3). consumeDigitcxx . . $ QTJSC/Yarr/Parser#consumeDigit(db52760e79bf9054).();
739 return n;
740 }
741
742 bool tryConsumecxx . . $ QTJSC/Yarr/Parser#tryConsume(3c978dac0e5ee2ad).(UCharcxx . . $ UChar# ch)
743 {
744 if (atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).() || (m_datacxx . . $ QTJSC/Yarr/Parser#m_data.[m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.] != ch))
745 return false;
746 ++m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.;
747 return true;
748 }
749
750 int tryConsumeHexcxx . . $ QTJSC/Yarr/Parser#tryConsumeHex(7864480464b09eea).(int count)
751 {
752 ParseStatecxx . . $ QTJSC/Yarr/Parser#ParseState# state = saveStatecxx . . $ QTJSC/Yarr/Parser#saveState(db52760e79bf9054).();
753
754 int n = 0;
755 while (count--) {
756 if (atEndOfPatterncxx . . $ QTJSC/Yarr/Parser#atEndOfPattern(c9857a73d68e59ba).() || !WTFcxx . . $ `<built-in>:467:9`!::isASCIIHexDigitcxx . . $ QTWTF/isASCIIHexDigit(3c978dac0e5ee2ad).(peekcxx . . $ QTJSC/Yarr/Parser#peek(b126dc7c1de90089).())) {
757 restoreStatecxx . . $ QTJSC/Yarr/Parser#restoreState(cb2f890c2fdad230).(state);
758 return -1;
759 }
760 n = (n << 4) |cxx . . $ `operator|`(68626a7e09ca3b35). WTFcxx . . $ `<built-in>:467:9`!::toASCIIHexValuecxx . . $ QTWTF/toASCIIHexValue(377f6a3136964dac).(consumecxx . . $ QTJSC/Yarr/Parser#consume(b126dc7c1de90089).());
761 }
762 return n;
763 }
764
765 Delegate& m_delegatecxx . . $ QTJSC/Yarr/Parser#m_delegate.;
766 unsigned m_backReferenceLimitcxx . . $ QTJSC/Yarr/Parser#m_backReferenceLimit.;
767 ErrorCodecxx . . $ QTJSC/Yarr/Parser#ErrorCode# m_errcxx . . $ QTJSC/Yarr/Parser#m_err.;
768 const UCharcxx . . $ UChar#* m_datacxx . . $ QTJSC/Yarr/Parser#m_data.;
769 unsigned m_sizecxx . . $ QTJSC/Yarr/Parser#m_size.;
770 unsigned m_indexcxx . . $ QTJSC/Yarr/Parser#m_index.;
771 unsigned m_parenthesesNestingDepthcxx . . $ QTJSC/Yarr/Parser#m_parenthesesNestingDepth.;
772
773 // Derived by empirical testing of compile time in PCRE and WREC.
774 static const unsigned MAX_PATTERN_SIZEcxx . . $ QTJSC/Yarr/Parser#MAX_PATTERN_SIZE. = 1024 * 1024;
775 };
776
777 /*
778 * Yarr::parse():
779 *
780 * The parse method is passed a pattern to be parsed and a delegate upon which
781 * callbacks will be made to record the parsed tokens forming the regex.
782 * Yarr::parse() returns null on success, or a const C string providing an error
783 * message where a parse error occurs.
784 *
785 * The Delegate must implement the following interface:
786 *
787 * void assertionBOL();
788 * void assertionEOL();
789 * void assertionWordBoundary(bool invert);
790 *
791 * void atomPatternCharacter(UChar ch);
792 * void atomBuiltInCharacterClass(BuiltInCharacterClassID classID, bool invert);
793 * void atomCharacterClassBegin(bool invert)
794 * void atomCharacterClassAtom(UChar ch)
795 * void atomCharacterClassRange(UChar begin, UChar end)
796 * void atomCharacterClassBuiltIn(BuiltInCharacterClassID classID, bool invert)
797 * void atomCharacterClassEnd()
798 * void atomParenthesesSubpatternBegin(bool capture = true);
799 * void atomParentheticalAssertionBegin(bool invert = false);
800 * void atomParenthesesEnd();
801 * void atomBackReference(unsigned subpatternId);
802 *
803 * void quantifyAtom(unsigned min, unsigned max, bool greedy);
804 *
805 * void disjunction();
806 *
807 * void regexBegin();
808 * void regexEnd();
809 * void regexError();
810 *
811 * Before any call recording tokens are made, regexBegin() will be called on the
812 * delegate once. Once parsing is complete either regexEnd() or regexError() will
813 * be called, as appropriate.
814 *
815 * The regular expression is described by a sequence of assertion*() and atom*()
816 * callbacks to the delegate, describing the terms in the regular expression.
817 * Following an atom a quantifyAtom() call may occur to indicate that the previous
818 * atom should be quantified. In the case of atoms described across multiple
819 * calls (parentheses and character classes) the call to quantifyAtom() will come
820 * after the call to the atom*End() method, never after atom*Begin().
821 *
822 * Character classes may either be described by a single call to
823 * atomBuiltInCharacterClass(), or by a sequence of atomCharacterClass*() calls.
824 * In the latter case, ...Begin() will be called, followed by a sequence of
825 * calls to ...Atom(), ...Range(), and ...BuiltIn(), followed by a call to ...End().
826 *
827 * Sequences of atoms and assertions are broken into alternatives via calls to
828 * disjunction(). Assertions, atoms, and disjunctions emitted between calls to
829 * atomParenthesesBegin() and atomParenthesesEnd() form the body of a subpattern.
830 * atomParenthesesBegin() is passed a subpatternId. In the case of a regular
831 * capturing subpattern, this will be the subpatternId associated with these
832 * parentheses, and will also by definition be the lowest subpatternId of these
833 * parentheses and of any nested paretheses. The atomParenthesesEnd() method
834 * is passed the subpatternId of the last capturing subexpression nested within
835 * these paretheses. In the case of a capturing subpattern with no nested
836 * capturing subpatterns, the same subpatternId will be passed to the begin and
837 * end functions. In the case of non-capturing subpatterns the subpatternId
838 * passed to the begin method is also the first possible subpatternId that might
839 * be nested within these paretheses. If a set of non-capturing parentheses does
840 * not contain any capturing subpatterns, then the subpatternId passed to begin
841 * will be greater than the subpatternId passed to end.
842 */
843
844 template<class Delegate>
845 const char* parsecxx . . $ QTJSC/Yarr/parse(8a54798a43a8c41c).(Delegate& delegate, const UStringcxx . . $ QTJSC/UString#& pattern, unsigned backReferenceLimit = UINT_MAXcxx . . $ `<external>/67164224788392828/limits.h:124:9`!)
846 {
847 return Parsercxx . . $ QTJSC/Yarr/Parser#<Delegate>(delegate, pattern, backReferenceLimit).parsecxx . . $ QTJSC/Yarr/Parser#parse(33a1f659e94feb42).();
848 }
849
850 } } // namespace JSC::Yarr
851
852 #endif
853
854 #endif // RegexParser_h