Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/3rdparty/masm/yarr/YarrParser.h |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 YarrParser_h | - | ||||||||||||||||||||||||
27 | #define YarrParser_h | - | ||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | #include "Yarr.h" | - | ||||||||||||||||||||||||
30 | #include <wtf/ASCIICType.h> | - | ||||||||||||||||||||||||
31 | #include <wtf/text/WTFString.h> | - | ||||||||||||||||||||||||
32 | #include <wtf/unicode/Unicode.h> | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | namespace JSC { namespace Yarr { | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | #define REGEXP_ERROR_PREFIX "Invalid regular expression: " | - | ||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||
38 | enum BuiltInCharacterClassID { | - | ||||||||||||||||||||||||
39 | DigitClassID, | - | ||||||||||||||||||||||||
40 | SpaceClassID, | - | ||||||||||||||||||||||||
41 | WordClassID, | - | ||||||||||||||||||||||||
42 | NewlineClassID, | - | ||||||||||||||||||||||||
43 | }; | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | // The Parser class should not be used directly - only via the Yarr::parse() method. | - | ||||||||||||||||||||||||
46 | template<class Delegate, typename CharType> | - | ||||||||||||||||||||||||
47 | class Parser { | - | ||||||||||||||||||||||||
48 | private: | - | ||||||||||||||||||||||||
49 | template<class FriendDelegate> | - | ||||||||||||||||||||||||
50 | friend const char* parse(FriendDelegate&, const String& pattern, unsigned backReferenceLimit); | - | ||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | enum ErrorCode { | - | ||||||||||||||||||||||||
53 | NoError, | - | ||||||||||||||||||||||||
54 | PatternTooLarge, | - | ||||||||||||||||||||||||
55 | QuantifierOutOfOrder, | - | ||||||||||||||||||||||||
56 | QuantifierWithoutAtom, | - | ||||||||||||||||||||||||
57 | QuantifierTooLarge, | - | ||||||||||||||||||||||||
58 | MissingParentheses, | - | ||||||||||||||||||||||||
59 | ParenthesesUnmatched, | - | ||||||||||||||||||||||||
60 | ParenthesesTypeInvalid, | - | ||||||||||||||||||||||||
61 | CharacterClassUnmatched, | - | ||||||||||||||||||||||||
62 | CharacterClassOutOfOrder, | - | ||||||||||||||||||||||||
63 | EscapeUnterminated, | - | ||||||||||||||||||||||||
64 | NumberOfErrorCodes | - | ||||||||||||||||||||||||
65 | }; | - | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | /* | - | ||||||||||||||||||||||||
68 | * CharacterClassParserDelegate: | - | ||||||||||||||||||||||||
69 | * | - | ||||||||||||||||||||||||
70 | * The class CharacterClassParserDelegate is used in the parsing of character | - | ||||||||||||||||||||||||
71 | * classes. This class handles detection of character ranges. This class | - | ||||||||||||||||||||||||
72 | * implements enough of the delegate interface such that it can be passed to | - | ||||||||||||||||||||||||
73 | * parseEscape() as an EscapeDelegate. This allows parseEscape() to be reused | - | ||||||||||||||||||||||||
74 | * to perform the parsing of escape characters in character sets. | - | ||||||||||||||||||||||||
75 | */ | - | ||||||||||||||||||||||||
76 | class CharacterClassParserDelegate { | - | ||||||||||||||||||||||||
77 | public: | - | ||||||||||||||||||||||||
78 | CharacterClassParserDelegate(Delegate& delegate, ErrorCode& err) | - | ||||||||||||||||||||||||
79 | : m_delegate(delegate) | - | ||||||||||||||||||||||||
80 | , m_err(err) | - | ||||||||||||||||||||||||
81 | , m_state(Empty) | - | ||||||||||||||||||||||||
82 | , m_character(0) | - | ||||||||||||||||||||||||
83 | { | - | ||||||||||||||||||||||||
84 | } executed 3557 times by 6 tests: end of block Executed by:
| 3557 | ||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | /* | - | ||||||||||||||||||||||||
87 | * begin(): | - | ||||||||||||||||||||||||
88 | * | - | ||||||||||||||||||||||||
89 | * Called at beginning of construction. | - | ||||||||||||||||||||||||
90 | */ | - | ||||||||||||||||||||||||
91 | void begin(bool invert) | - | ||||||||||||||||||||||||
92 | { | - | ||||||||||||||||||||||||
93 | m_delegate.atomCharacterClassBegin(invert); | - | ||||||||||||||||||||||||
94 | } executed 3558 times by 6 tests: end of block Executed by:
| 3558 | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | /* | - | ||||||||||||||||||||||||
97 | * atomPatternCharacter(): | - | ||||||||||||||||||||||||
98 | * | - | ||||||||||||||||||||||||
99 | * This method is called either from parseCharacterClass() (for an unescaped | - | ||||||||||||||||||||||||
100 | * character in a character class), or from parseEscape(). In the former case | - | ||||||||||||||||||||||||
101 | * the value true will be passed for the argument 'hyphenIsRange', and in this | - | ||||||||||||||||||||||||
102 | * mode we will allow a hypen to be treated as indicating a range (i.e. /[a-z]/ | - | ||||||||||||||||||||||||
103 | * is different to /[a\-z]/). | - | ||||||||||||||||||||||||
104 | */ | - | ||||||||||||||||||||||||
105 | void atomPatternCharacter(UChar ch, bool hyphenIsRange = false) | - | ||||||||||||||||||||||||
106 | { | - | ||||||||||||||||||||||||
107 | switch (m_state) { | - | ||||||||||||||||||||||||
108 | case AfterCharacterClass: executed 32 times by 1 test: case AfterCharacterClass: Executed by:
| 32 | ||||||||||||||||||||||||
109 | // Following a builtin character class we need look out for a hyphen. | - | ||||||||||||||||||||||||
110 | // We're looking for invalid ranges, such as /[\d-x]/ or /[\d-\d]/. | - | ||||||||||||||||||||||||
111 | // If we see a hyphen following a charater class then unlike usual | - | ||||||||||||||||||||||||
112 | // we'll report it to the delegate immediately, and put ourself into | - | ||||||||||||||||||||||||
113 | // a poisoned state. Any following calls to add another character or | - | ||||||||||||||||||||||||
114 | // character class will result in an error. (A hypen following a | - | ||||||||||||||||||||||||
115 | // character-class is itself valid, but only at the end of a regex). | - | ||||||||||||||||||||||||
116 | if (hyphenIsRange && ch == '-') {
| 0-28 | ||||||||||||||||||||||||
117 | m_delegate.atomCharacterClassAtom('-'); | - | ||||||||||||||||||||||||
118 | m_state = AfterCharacterClassHyphen; | - | ||||||||||||||||||||||||
119 | return; never executed: return; | 0 | ||||||||||||||||||||||||
120 | } | - | ||||||||||||||||||||||||
121 | Q_FALLTHROUGH(); // cached character, so treat this as Empty. | - | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | case Empty: code before this statement executed 32 times by 1 test: case Empty: Executed by:
executed 2847 times by 6 tests: case Empty: Executed by:
| 32-2847 | ||||||||||||||||||||||||
124 | m_character = ch; | - | ||||||||||||||||||||||||
125 | m_state = CachedCharacter; | - | ||||||||||||||||||||||||
126 | return; executed 2880 times by 6 tests: return; Executed by:
| 2880 | ||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||
128 | case CachedCharacter: executed 3808 times by 6 tests: case CachedCharacter: Executed by:
| 3808 | ||||||||||||||||||||||||
129 | if (hyphenIsRange && ch == '-')
| 628-3180 | ||||||||||||||||||||||||
130 | m_state = CachedCharacterHyphen; executed 1682 times by 5 tests: m_state = CachedCharacterHyphen; Executed by:
| 1682 | ||||||||||||||||||||||||
131 | else { | - | ||||||||||||||||||||||||
132 | m_delegate.atomCharacterClassAtom(m_character); | - | ||||||||||||||||||||||||
133 | m_character = ch; | - | ||||||||||||||||||||||||
134 | } executed 2126 times by 3 tests: end of block Executed by:
| 2126 | ||||||||||||||||||||||||
135 | return; executed 3806 times by 6 tests: return; Executed by:
| 3806 | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | case CachedCharacterHyphen: executed 1535 times by 5 tests: case CachedCharacterHyphen: Executed by:
| 1535 | ||||||||||||||||||||||||
138 | if (ch < m_character) {
| 176-1359 | ||||||||||||||||||||||||
139 | m_err = CharacterClassOutOfOrder; | - | ||||||||||||||||||||||||
140 | return; executed 176 times by 1 test: return; Executed by:
| 176 | ||||||||||||||||||||||||
141 | } | - | ||||||||||||||||||||||||
142 | m_delegate.atomCharacterClassRange(m_character, ch); | - | ||||||||||||||||||||||||
143 | m_state = Empty; | - | ||||||||||||||||||||||||
144 | return; executed 1359 times by 5 tests: return; Executed by:
| 1359 | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | // See coment in atomBuiltInCharacterClass below. | - | ||||||||||||||||||||||||
147 | // This too is technically an error, per ECMA-262, and again we | - | ||||||||||||||||||||||||
148 | // we chose to allow this. Note a subtlely here that while we | - | ||||||||||||||||||||||||
149 | // diverge from the spec's definition of CharacterRange we do | - | ||||||||||||||||||||||||
150 | // remain in compliance with the grammar. For example, consider | - | ||||||||||||||||||||||||
151 | // the expression /[\d-a-z]/. We comply with the grammar in | - | ||||||||||||||||||||||||
152 | // this case by not allowing a-z to be matched as a range. | - | ||||||||||||||||||||||||
153 | case AfterCharacterClassHyphen: never executed: case AfterCharacterClassHyphen: | 0 | ||||||||||||||||||||||||
154 | m_delegate.atomCharacterClassAtom(ch); | - | ||||||||||||||||||||||||
155 | m_state = Empty; | - | ||||||||||||||||||||||||
156 | return; never executed: return; | 0 | ||||||||||||||||||||||||
157 | } | - | ||||||||||||||||||||||||
158 | } never executed: end of block | 0 | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | /* | - | ||||||||||||||||||||||||
161 | * atomBuiltInCharacterClass(): | - | ||||||||||||||||||||||||
162 | * | - | ||||||||||||||||||||||||
163 | * Adds a built-in character class, called by parseEscape(). | - | ||||||||||||||||||||||||
164 | */ | - | ||||||||||||||||||||||||
165 | void atomBuiltInCharacterClass(BuiltInCharacterClassID classID, bool invert) | - | ||||||||||||||||||||||||
166 | { | - | ||||||||||||||||||||||||
167 | switch (m_state) { | - | ||||||||||||||||||||||||
168 | case CachedCharacter: never executed: case CachedCharacter: | 0 | ||||||||||||||||||||||||
169 | // Flush the currently cached character, then fall through. | - | ||||||||||||||||||||||||
170 | m_delegate.atomCharacterClassAtom(m_character); | - | ||||||||||||||||||||||||
171 | Q_FALLTHROUGH(); | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | case Empty: code before this statement never executed: case Empty: executed 1407 times by 1 test: case Empty: Executed by:
| 0-1407 | ||||||||||||||||||||||||
174 | case AfterCharacterClass: executed 1248 times by 1 test: case AfterCharacterClass: Executed by:
| 1248 | ||||||||||||||||||||||||
175 | m_state = AfterCharacterClass; | - | ||||||||||||||||||||||||
176 | m_delegate.atomCharacterClassBuiltIn(classID, invert); | - | ||||||||||||||||||||||||
177 | return; executed 2656 times by 1 test: return; Executed by:
| 2656 | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | // If we hit either of these cases, we have an invalid range that | - | ||||||||||||||||||||||||
180 | // looks something like /[x-\d]/ or /[\d-\d]/. | - | ||||||||||||||||||||||||
181 | // According to ECMA-262 this should be a syntax error, but | - | ||||||||||||||||||||||||
182 | // empirical testing shows this to break teh webz. Instead we | - | ||||||||||||||||||||||||
183 | // comply with to the ECMA-262 grammar, and assume the grammar to | - | ||||||||||||||||||||||||
184 | // have matched the range correctly, but tweak our interpretation | - | ||||||||||||||||||||||||
185 | // of CharacterRange. Effectively we implicitly handle the hyphen | - | ||||||||||||||||||||||||
186 | // as if it were escaped, e.g. /[\w-_]/ is treated as /[\w\-_]/. | - | ||||||||||||||||||||||||
187 | case CachedCharacterHyphen: never executed: case CachedCharacterHyphen: | 0 | ||||||||||||||||||||||||
188 | m_delegate.atomCharacterClassAtom(m_character); | - | ||||||||||||||||||||||||
189 | m_delegate.atomCharacterClassAtom('-'); | - | ||||||||||||||||||||||||
190 | // fall through | - | ||||||||||||||||||||||||
191 | case AfterCharacterClassHyphen: code before this statement never executed: case AfterCharacterClassHyphen: never executed: case AfterCharacterClassHyphen: | 0 | ||||||||||||||||||||||||
192 | m_delegate.atomCharacterClassBuiltIn(classID, invert); | - | ||||||||||||||||||||||||
193 | m_state = Empty; | - | ||||||||||||||||||||||||
194 | return; never executed: return; | 0 | ||||||||||||||||||||||||
195 | } | - | ||||||||||||||||||||||||
196 | } never executed: end of block | 0 | ||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | /* | - | ||||||||||||||||||||||||
199 | * end(): | - | ||||||||||||||||||||||||
200 | * | - | ||||||||||||||||||||||||
201 | * Called at end of construction. | - | ||||||||||||||||||||||||
202 | */ | - | ||||||||||||||||||||||||
203 | void end() | - | ||||||||||||||||||||||||
204 | { | - | ||||||||||||||||||||||||
205 | if (m_state == CachedCharacter)
| 1202-2182 | ||||||||||||||||||||||||
206 | m_delegate.atomCharacterClassAtom(m_character); executed 1202 times by 3 tests: m_delegate.atomCharacterClassAtom(m_character); Executed by:
| 1202 | ||||||||||||||||||||||||
207 | else if (m_state == CachedCharacterHyphen) {
| 146-2036 | ||||||||||||||||||||||||
208 | m_delegate.atomCharacterClassAtom(m_character); | - | ||||||||||||||||||||||||
209 | m_delegate.atomCharacterClassAtom('-'); | - | ||||||||||||||||||||||||
210 | } executed 146 times by 2 tests: end of block Executed by:
| 146 | ||||||||||||||||||||||||
211 | m_delegate.atomCharacterClassEnd(); | - | ||||||||||||||||||||||||
212 | } executed 3384 times by 6 tests: end of block Executed by:
| 3384 | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | // parseEscape() should never call these delegate methods when | - | ||||||||||||||||||||||||
215 | // invoked with inCharacterClass set. | - | ||||||||||||||||||||||||
216 | NO_RETURN_DUE_TO_ASSERT void assertionWordBoundary(bool) { RELEASE_ASSERT_NOT_REACHED(); } never executed: end of block | 0 | ||||||||||||||||||||||||
217 | NO_RETURN_DUE_TO_ASSERT void atomBackReference(unsigned) { RELEASE_ASSERT_NOT_REACHED(); } never executed: end of block | 0 | ||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||
219 | private: | - | ||||||||||||||||||||||||
220 | Delegate& m_delegate; | - | ||||||||||||||||||||||||
221 | ErrorCode& m_err; | - | ||||||||||||||||||||||||
222 | enum CharacterClassConstructionState { | - | ||||||||||||||||||||||||
223 | Empty, | - | ||||||||||||||||||||||||
224 | CachedCharacter, | - | ||||||||||||||||||||||||
225 | CachedCharacterHyphen, | - | ||||||||||||||||||||||||
226 | AfterCharacterClass, | - | ||||||||||||||||||||||||
227 | AfterCharacterClassHyphen, | - | ||||||||||||||||||||||||
228 | } m_state; | - | ||||||||||||||||||||||||
229 | UChar m_character; | - | ||||||||||||||||||||||||
230 | }; | - | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | Parser(Delegate& delegate, const String& pattern, unsigned backReferenceLimit) | - | ||||||||||||||||||||||||
233 | : m_delegate(delegate) | - | ||||||||||||||||||||||||
234 | , m_backReferenceLimit(backReferenceLimit) | - | ||||||||||||||||||||||||
235 | , m_err(NoError) | - | ||||||||||||||||||||||||
236 | , m_data(pattern.getCharacters<CharType>()) | - | ||||||||||||||||||||||||
237 | , m_size(pattern.length()) | - | ||||||||||||||||||||||||
238 | , m_index(0) | - | ||||||||||||||||||||||||
239 | , m_parenthesesNestingDepth(0) | - | ||||||||||||||||||||||||
240 | { | - | ||||||||||||||||||||||||
241 | } executed 1149133 times by 153 tests: end of block Executed by:
| 1149133 | ||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||
243 | /* | - | ||||||||||||||||||||||||
244 | * parseEscape(): | - | ||||||||||||||||||||||||
245 | * | - | ||||||||||||||||||||||||
246 | * Helper for parseTokens() AND parseCharacterClass(). | - | ||||||||||||||||||||||||
247 | * Unlike the other parser methods, this function does not report tokens | - | ||||||||||||||||||||||||
248 | * directly to the member delegate (m_delegate), instead tokens are | - | ||||||||||||||||||||||||
249 | * emitted to the delegate provided as an argument. In the case of atom | - | ||||||||||||||||||||||||
250 | * escapes, parseTokens() will call parseEscape() passing m_delegate as | - | ||||||||||||||||||||||||
251 | * an argument, and as such the escape will be reported to the delegate. | - | ||||||||||||||||||||||||
252 | * | - | ||||||||||||||||||||||||
253 | * However this method may also be used by parseCharacterClass(), in which | - | ||||||||||||||||||||||||
254 | * case a CharacterClassParserDelegate will be passed as the delegate that | - | ||||||||||||||||||||||||
255 | * tokens should be added to. A boolean flag is also provided to indicate | - | ||||||||||||||||||||||||
256 | * whether that an escape in a CharacterClass is being parsed (some parsing | - | ||||||||||||||||||||||||
257 | * rules change in this context). | - | ||||||||||||||||||||||||
258 | * | - | ||||||||||||||||||||||||
259 | * The boolean value returned by this method indicates whether the token | - | ||||||||||||||||||||||||
260 | * parsed was an atom (outside of a characted class \b and \B will be | - | ||||||||||||||||||||||||
261 | * interpreted as assertions). | - | ||||||||||||||||||||||||
262 | */ | - | ||||||||||||||||||||||||
263 | template<bool inCharacterClass, class EscapeDelegate> | - | ||||||||||||||||||||||||
264 | bool parseEscape(EscapeDelegate& delegate) | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | ASSERT(!m_err); | - | ||||||||||||||||||||||||
267 | ASSERT(peek() == '\\'); | - | ||||||||||||||||||||||||
268 | consume(); | - | ||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||
270 | if (atEndOfPattern()) {
| 4-532695 | ||||||||||||||||||||||||
271 | m_err = EscapeUnterminated; | - | ||||||||||||||||||||||||
272 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||||||||
273 | } | - | ||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||
275 | switch (peek()) { | - | ||||||||||||||||||||||||
276 | // Assertions | - | ||||||||||||||||||||||||
277 | case 'b': executed 1076 times by 1 test: case 'b': Executed by:
| 1076 | ||||||||||||||||||||||||
278 | consume(); | - | ||||||||||||||||||||||||
279 | if (inCharacterClass)
| 24-1052 | ||||||||||||||||||||||||
280 | delegate.atomPatternCharacter('\b'); executed 24 times by 1 test: delegate.atomPatternCharacter('\b'); Executed by:
| 24 | ||||||||||||||||||||||||
281 | else { | - | ||||||||||||||||||||||||
282 | delegate.assertionWordBoundary(false); | - | ||||||||||||||||||||||||
283 | return false; executed 1052 times by 1 test: return false; Executed by:
| 1052 | ||||||||||||||||||||||||
284 | } | - | ||||||||||||||||||||||||
285 | break; executed 24 times by 1 test: break; Executed by:
| 24 | ||||||||||||||||||||||||
286 | case 'B': executed 87 times by 1 test: case 'B': Executed by:
| 87 | ||||||||||||||||||||||||
287 | consume(); | - | ||||||||||||||||||||||||
288 | if (inCharacterClass)
| 4-83 | ||||||||||||||||||||||||
289 | delegate.atomPatternCharacter('B'); executed 4 times by 1 test: delegate.atomPatternCharacter('B'); Executed by:
| 4 | ||||||||||||||||||||||||
290 | else { | - | ||||||||||||||||||||||||
291 | delegate.assertionWordBoundary(true); | - | ||||||||||||||||||||||||
292 | return false; executed 84 times by 1 test: return false; Executed by:
| 84 | ||||||||||||||||||||||||
293 | } | - | ||||||||||||||||||||||||
294 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||
296 | // CharacterClassEscape | - | ||||||||||||||||||||||||
297 | case 'd': executed 370 times by 3 tests: case 'd': Executed by:
| 370 | ||||||||||||||||||||||||
298 | consume(); | - | ||||||||||||||||||||||||
299 | delegate.atomBuiltInCharacterClass(DigitClassID, false); | - | ||||||||||||||||||||||||
300 | break; executed 369 times by 3 tests: break; Executed by:
| 369 | ||||||||||||||||||||||||
301 | case 's': executed 1390 times by 3 tests: case 's': Executed by:
| 1390 | ||||||||||||||||||||||||
302 | consume(); | - | ||||||||||||||||||||||||
303 | delegate.atomBuiltInCharacterClass(SpaceClassID, false); | - | ||||||||||||||||||||||||
304 | break; executed 1390 times by 3 tests: break; Executed by:
| 1390 | ||||||||||||||||||||||||
305 | case 'w': executed 104 times by 1 test: case 'w': Executed by:
| 104 | ||||||||||||||||||||||||
306 | consume(); | - | ||||||||||||||||||||||||
307 | delegate.atomBuiltInCharacterClass(WordClassID, false); | - | ||||||||||||||||||||||||
308 | break; executed 104 times by 1 test: break; Executed by:
| 104 | ||||||||||||||||||||||||
309 | case 'D': executed 36 times by 1 test: case 'D': Executed by:
| 36 | ||||||||||||||||||||||||
310 | consume(); | - | ||||||||||||||||||||||||
311 | delegate.atomBuiltInCharacterClass(DigitClassID, true); | - | ||||||||||||||||||||||||
312 | break; executed 36 times by 1 test: break; Executed by:
| 36 | ||||||||||||||||||||||||
313 | case 'S': executed 1304 times by 1 test: case 'S': Executed by:
| 1304 | ||||||||||||||||||||||||
314 | consume(); | - | ||||||||||||||||||||||||
315 | delegate.atomBuiltInCharacterClass(SpaceClassID, true); | - | ||||||||||||||||||||||||
316 | break; executed 1304 times by 1 test: break; Executed by:
| 1304 | ||||||||||||||||||||||||
317 | case 'W': executed 36 times by 1 test: case 'W': Executed by:
| 36 | ||||||||||||||||||||||||
318 | consume(); | - | ||||||||||||||||||||||||
319 | delegate.atomBuiltInCharacterClass(WordClassID, true); | - | ||||||||||||||||||||||||
320 | break; executed 36 times by 1 test: break; Executed by:
| 36 | ||||||||||||||||||||||||
321 | - | |||||||||||||||||||||||||
322 | // DecimalEscape | - | ||||||||||||||||||||||||
323 | case '1': executed 116 times by 1 test: case '1': Executed by:
| 116 | ||||||||||||||||||||||||
324 | case '2': executed 48 times by 1 test: case '2': Executed by:
| 48 | ||||||||||||||||||||||||
325 | case '3': executed 24 times by 1 test: case '3': Executed by:
| 24 | ||||||||||||||||||||||||
326 | case '4': executed 24 times by 1 test: case '4': Executed by:
| 24 | ||||||||||||||||||||||||
327 | case '5': executed 28 times by 1 test: case '5': Executed by:
| 28 | ||||||||||||||||||||||||
328 | case '6': executed 24 times by 1 test: case '6': Executed by:
| 24 | ||||||||||||||||||||||||
329 | case '7': executed 24 times by 1 test: case '7': Executed by:
| 24 | ||||||||||||||||||||||||
330 | case '8': executed 24 times by 1 test: case '8': Executed by:
| 24 | ||||||||||||||||||||||||
331 | case '9': { executed 24 times by 1 test: case '9': Executed by:
| 24 | ||||||||||||||||||||||||
332 | // To match Firefox, we parse an invalid backreference in the range [1-7] as an octal escape. | - | ||||||||||||||||||||||||
333 | // First, try to parse this as backreference. | - | ||||||||||||||||||||||||
334 | if (!inCharacterClass) {
| 4-332 | ||||||||||||||||||||||||
335 | ParseState state = saveState(); | - | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | unsigned backReference = consumeNumber(); | - | ||||||||||||||||||||||||
338 | if (backReference <= m_backReferenceLimit) {
| 72-260 | ||||||||||||||||||||||||
339 | delegate.atomBackReference(backReference); | - | ||||||||||||||||||||||||
340 | break; executed 260 times by 1 test: break; Executed by:
| 260 | ||||||||||||||||||||||||
341 | } | - | ||||||||||||||||||||||||
342 | - | |||||||||||||||||||||||||
343 | restoreState(state); | - | ||||||||||||||||||||||||
344 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | // Not a backreference, and not octal. | - | ||||||||||||||||||||||||
347 | if (peek() >= '8') {
| 16-60 | ||||||||||||||||||||||||
348 | delegate.atomPatternCharacter('\\'); | - | ||||||||||||||||||||||||
349 | break; executed 16 times by 1 test: break; Executed by:
| 16 | ||||||||||||||||||||||||
350 | } | - | ||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||
352 | Q_FALLTHROUGH(); // Handle this as an octal escape. | - | ||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||
354 | // Octal escape | - | ||||||||||||||||||||||||
355 | case '0': code before this statement executed 60 times by 1 test: case '0': Executed by:
executed 16 times by 1 test: case '0': Executed by:
| 16-60 | ||||||||||||||||||||||||
356 | delegate.atomPatternCharacter(consumeOctal()); | - | ||||||||||||||||||||||||
357 | break; executed 76 times by 1 test: break; Executed by:
| 76 | ||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||
359 | // ControlEscape | - | ||||||||||||||||||||||||
360 | case 'f': executed 24 times by 1 test: case 'f': Executed by:
| 24 | ||||||||||||||||||||||||
361 | consume(); | - | ||||||||||||||||||||||||
362 | delegate.atomPatternCharacter('\f'); | - | ||||||||||||||||||||||||
363 | break; executed 24 times by 1 test: break; Executed by:
| 24 | ||||||||||||||||||||||||
364 | case 'n': executed 232 times by 1 test: case 'n': Executed by:
| 232 | ||||||||||||||||||||||||
365 | consume(); | - | ||||||||||||||||||||||||
366 | delegate.atomPatternCharacter('\n'); | - | ||||||||||||||||||||||||
367 | break; executed 232 times by 1 test: break; Executed by:
| 232 | ||||||||||||||||||||||||
368 | case 'r': executed 220 times by 1 test: case 'r': Executed by:
| 220 | ||||||||||||||||||||||||
369 | consume(); | - | ||||||||||||||||||||||||
370 | delegate.atomPatternCharacter('\r'); | - | ||||||||||||||||||||||||
371 | break; executed 220 times by 1 test: break; Executed by:
| 220 | ||||||||||||||||||||||||
372 | case 't': executed 236 times by 1 test: case 't': Executed by:
| 236 | ||||||||||||||||||||||||
373 | consume(); | - | ||||||||||||||||||||||||
374 | delegate.atomPatternCharacter('\t'); | - | ||||||||||||||||||||||||
375 | break; executed 236 times by 1 test: break; Executed by:
| 236 | ||||||||||||||||||||||||
376 | case 'v': executed 24 times by 1 test: case 'v': Executed by:
| 24 | ||||||||||||||||||||||||
377 | consume(); | - | ||||||||||||||||||||||||
378 | delegate.atomPatternCharacter('\v'); | - | ||||||||||||||||||||||||
379 | break; executed 24 times by 1 test: break; Executed by:
| 24 | ||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||
381 | // ControlLetter | - | ||||||||||||||||||||||||
382 | case 'c': { executed 220 times by 1 test: case 'c': Executed by:
| 220 | ||||||||||||||||||||||||
383 | ParseState state = saveState(); | - | ||||||||||||||||||||||||
384 | consume(); | - | ||||||||||||||||||||||||
385 | if (!atEndOfPattern()) {
| 8-212 | ||||||||||||||||||||||||
386 | int control = consume(); | - | ||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||
388 | // To match Firefox, inside a character class, we also accept numbers and '_' as control characters. | - | ||||||||||||||||||||||||
389 | if (inCharacterClass ? WTF::isASCIIAlphanumeric(control) || (control == '_') : WTF::isASCIIAlpha(control)) {
| 0-212 | ||||||||||||||||||||||||
390 | delegate.atomPatternCharacter(control & 0x1f); | - | ||||||||||||||||||||||||
391 | break; executed 212 times by 1 test: break; Executed by:
| 212 | ||||||||||||||||||||||||
392 | } | - | ||||||||||||||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||||||||||||||
394 | restoreState(state); | - | ||||||||||||||||||||||||
395 | delegate.atomPatternCharacter('\\'); | - | ||||||||||||||||||||||||
396 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||
397 | } | - | ||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||
399 | // HexEscape | - | ||||||||||||||||||||||||
400 | case 'x': { executed 788 times by 1 test: case 'x': Executed by:
| 788 | ||||||||||||||||||||||||
401 | consume(); | - | ||||||||||||||||||||||||
402 | int x = tryConsumeHex(2); | - | ||||||||||||||||||||||||
403 | if (x == -1)
| 8-780 | ||||||||||||||||||||||||
404 | delegate.atomPatternCharacter('x'); executed 8 times by 1 test: delegate.atomPatternCharacter('x'); Executed by:
| 8 | ||||||||||||||||||||||||
405 | else | - | ||||||||||||||||||||||||
406 | delegate.atomPatternCharacter(x); executed 780 times by 1 test: delegate.atomPatternCharacter(x); Executed by:
| 780 | ||||||||||||||||||||||||
407 | break; executed 788 times by 1 test: break; Executed by:
| 788 | ||||||||||||||||||||||||
408 | } | - | ||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | // UnicodeEscape | - | ||||||||||||||||||||||||
411 | case 'u': { executed 539 times by 1 test: case 'u': Executed by:
| 539 | ||||||||||||||||||||||||
412 | consume(); | - | ||||||||||||||||||||||||
413 | int u = tryConsumeHex(4); | - | ||||||||||||||||||||||||
414 | if (u == -1)
| 8-531 | ||||||||||||||||||||||||
415 | delegate.atomPatternCharacter('u'); executed 8 times by 1 test: delegate.atomPatternCharacter('u'); Executed by:
| 8 | ||||||||||||||||||||||||
416 | else | - | ||||||||||||||||||||||||
417 | delegate.atomPatternCharacter(u); executed 531 times by 1 test: delegate.atomPatternCharacter(u); Executed by:
| 531 | ||||||||||||||||||||||||
418 | break; executed 540 times by 1 test: break; Executed by:
| 540 | ||||||||||||||||||||||||
419 | } | - | ||||||||||||||||||||||||
420 | - | |||||||||||||||||||||||||
421 | // IdentityEscape | - | ||||||||||||||||||||||||
422 | default: executed 525653 times by 3 tests: default: Executed by:
| 525653 | ||||||||||||||||||||||||
423 | delegate.atomPatternCharacter(consume()); | - | ||||||||||||||||||||||||
424 | } executed 525668 times by 3 tests: end of block Executed by:
| 525668 | ||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||
426 | return true; executed 531567 times by 5 tests: return true; Executed by:
| 531567 | ||||||||||||||||||||||||
427 | } | - | ||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||
429 | /* | - | ||||||||||||||||||||||||
430 | * parseAtomEscape(), parseCharacterClassEscape(): | - | ||||||||||||||||||||||||
431 | * | - | ||||||||||||||||||||||||
432 | * These methods alias to parseEscape(). | - | ||||||||||||||||||||||||
433 | */ | - | ||||||||||||||||||||||||
434 | bool parseAtomEscape() | - | ||||||||||||||||||||||||
435 | { | - | ||||||||||||||||||||||||
436 | return parseEscape<false>(m_delegate); executed 528636 times by 5 tests: return parseEscape<false>(m_delegate); Executed by:
| 528636 | ||||||||||||||||||||||||
437 | } | - | ||||||||||||||||||||||||
438 | void parseCharacterClassEscape(CharacterClassParserDelegate& delegate) | - | ||||||||||||||||||||||||
439 | { | - | ||||||||||||||||||||||||
440 | parseEscape<true>(delegate); | - | ||||||||||||||||||||||||
441 | } executed 4068 times by 1 test: end of block Executed by:
| 4068 | ||||||||||||||||||||||||
442 | - | |||||||||||||||||||||||||
443 | /* | - | ||||||||||||||||||||||||
444 | * parseCharacterClass(): | - | ||||||||||||||||||||||||
445 | * | - | ||||||||||||||||||||||||
446 | * Helper for parseTokens(); calls dirctly and indirectly (via parseCharacterClassEscape) | - | ||||||||||||||||||||||||
447 | * to an instance of CharacterClassParserDelegate, to describe the character class to the | - | ||||||||||||||||||||||||
448 | * delegate. | - | ||||||||||||||||||||||||
449 | */ | - | ||||||||||||||||||||||||
450 | void parseCharacterClass() | - | ||||||||||||||||||||||||
451 | { | - | ||||||||||||||||||||||||
452 | ASSERT(!m_err); | - | ||||||||||||||||||||||||
453 | ASSERT(peek() == '['); | - | ||||||||||||||||||||||||
454 | consume(); | - | ||||||||||||||||||||||||
455 | - | |||||||||||||||||||||||||
456 | CharacterClassParserDelegate characterClassConstructor(m_delegate, m_err); | - | ||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | characterClassConstructor.begin(tryConsume('^')); | - | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | while (!atEndOfPattern()) {
| 0-14263 | ||||||||||||||||||||||||
461 | switch (peek()) { | - | ||||||||||||||||||||||||
462 | case ']': executed 3384 times by 6 tests: case ']': Executed by:
| 3384 | ||||||||||||||||||||||||
463 | consume(); | - | ||||||||||||||||||||||||
464 | characterClassConstructor.end(); | - | ||||||||||||||||||||||||
465 | return; executed 3384 times by 6 tests: return; Executed by:
| 3384 | ||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||
467 | case '\\': executed 4068 times by 1 test: case '\\': Executed by:
| 4068 | ||||||||||||||||||||||||
468 | parseCharacterClassEscape(characterClassConstructor); | - | ||||||||||||||||||||||||
469 | break; executed 4068 times by 1 test: break; Executed by:
| 4068 | ||||||||||||||||||||||||
470 | - | |||||||||||||||||||||||||
471 | default: executed 6809 times by 6 tests: default: Executed by:
| 6809 | ||||||||||||||||||||||||
472 | characterClassConstructor.atomPatternCharacter(consume(), true); | - | ||||||||||||||||||||||||
473 | } executed 6810 times by 6 tests: end of block Executed by:
| 6810 | ||||||||||||||||||||||||
474 | - | |||||||||||||||||||||||||
475 | if (m_err)
| 176-10703 | ||||||||||||||||||||||||
476 | return; executed 176 times by 1 test: return; Executed by:
| 176 | ||||||||||||||||||||||||
477 | } executed 10705 times by 6 tests: end of block Executed by:
| 10705 | ||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||
479 | m_err = CharacterClassUnmatched; | - | ||||||||||||||||||||||||
480 | } never executed: end of block | 0 | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | /* | - | ||||||||||||||||||||||||
483 | * parseParenthesesBegin(): | - | ||||||||||||||||||||||||
484 | * | - | ||||||||||||||||||||||||
485 | * Helper for parseTokens(); checks for parentheses types other than regular capturing subpatterns. | - | ||||||||||||||||||||||||
486 | */ | - | ||||||||||||||||||||||||
487 | void parseParenthesesBegin() | - | ||||||||||||||||||||||||
488 | { | - | ||||||||||||||||||||||||
489 | ASSERT(!m_err); | - | ||||||||||||||||||||||||
490 | ASSERT(peek() == '('); | - | ||||||||||||||||||||||||
491 | consume(); | - | ||||||||||||||||||||||||
492 | - | |||||||||||||||||||||||||
493 | if (tryConsume('?')) {
| 1027-2548 | ||||||||||||||||||||||||
494 | if (atEndOfPattern()) {
| 0-1027 | ||||||||||||||||||||||||
495 | m_err = ParenthesesTypeInvalid; | - | ||||||||||||||||||||||||
496 | return; never executed: return; | 0 | ||||||||||||||||||||||||
497 | } | - | ||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||
499 | switch (consume()) { | - | ||||||||||||||||||||||||
500 | case ':': executed 951 times by 1 test: case ':': Executed by:
| 951 | ||||||||||||||||||||||||
501 | m_delegate.atomParenthesesSubpatternBegin(false); | - | ||||||||||||||||||||||||
502 | break; executed 952 times by 1 test: break; Executed by:
| 952 | ||||||||||||||||||||||||
503 | - | |||||||||||||||||||||||||
504 | case '=': executed 32 times by 1 test: case '=': Executed by:
| 32 | ||||||||||||||||||||||||
505 | m_delegate.atomParentheticalAssertionBegin(); | - | ||||||||||||||||||||||||
506 | break; executed 32 times by 1 test: break; Executed by:
| 32 | ||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | case '!': executed 44 times by 1 test: case '!': Executed by:
| 44 | ||||||||||||||||||||||||
509 | m_delegate.atomParentheticalAssertionBegin(true); | - | ||||||||||||||||||||||||
510 | break; executed 44 times by 1 test: break; Executed by:
| 44 | ||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | default: never executed: default: | 0 | ||||||||||||||||||||||||
513 | m_err = ParenthesesTypeInvalid; | - | ||||||||||||||||||||||||
514 | } never executed: end of block | 0 | ||||||||||||||||||||||||
515 | } else | - | ||||||||||||||||||||||||
516 | m_delegate.atomParenthesesSubpatternBegin(); executed 2548 times by 3 tests: m_delegate.atomParenthesesSubpatternBegin(); Executed by:
| 2548 | ||||||||||||||||||||||||
517 | - | |||||||||||||||||||||||||
518 | ++m_parenthesesNestingDepth; | - | ||||||||||||||||||||||||
519 | } executed 3577 times by 3 tests: end of block Executed by:
| 3577 | ||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||
521 | /* | - | ||||||||||||||||||||||||
522 | * parseParenthesesEnd(): | - | ||||||||||||||||||||||||
523 | * | - | ||||||||||||||||||||||||
524 | * Helper for parseTokens(); checks for parse errors (due to unmatched parentheses). | - | ||||||||||||||||||||||||
525 | */ | - | ||||||||||||||||||||||||
526 | void parseParenthesesEnd() | - | ||||||||||||||||||||||||
527 | { | - | ||||||||||||||||||||||||
528 | ASSERT(!m_err); | - | ||||||||||||||||||||||||
529 | ASSERT(peek() == ')'); | - | ||||||||||||||||||||||||
530 | consume(); | - | ||||||||||||||||||||||||
531 | - | |||||||||||||||||||||||||
532 | if (m_parenthesesNestingDepth > 0)
| 0-3577 | ||||||||||||||||||||||||
533 | m_delegate.atomParenthesesEnd(); executed 3577 times by 3 tests: m_delegate.atomParenthesesEnd(); Executed by:
| 3577 | ||||||||||||||||||||||||
534 | else | - | ||||||||||||||||||||||||
535 | m_err = ParenthesesUnmatched; never executed: m_err = ParenthesesUnmatched; | 0 | ||||||||||||||||||||||||
536 | - | |||||||||||||||||||||||||
537 | --m_parenthesesNestingDepth; | - | ||||||||||||||||||||||||
538 | } executed 3575 times by 3 tests: end of block Executed by:
| 3575 | ||||||||||||||||||||||||
539 | - | |||||||||||||||||||||||||
540 | /* | - | ||||||||||||||||||||||||
541 | * parseQuantifier(): | - | ||||||||||||||||||||||||
542 | * | - | ||||||||||||||||||||||||
543 | * Helper for parseTokens(); checks for parse errors and non-greedy quantifiers. | - | ||||||||||||||||||||||||
544 | */ | - | ||||||||||||||||||||||||
545 | void parseQuantifier(bool lastTokenWasAnAtom, unsigned min, unsigned max) | - | ||||||||||||||||||||||||
546 | { | - | ||||||||||||||||||||||||
547 | ASSERT(!m_err); | - | ||||||||||||||||||||||||
548 | ASSERT(min <= max); | - | ||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||
550 | if (min == UINT_MAX) {
| 0-4209 | ||||||||||||||||||||||||
551 | m_err = QuantifierTooLarge; | - | ||||||||||||||||||||||||
552 | return; never executed: return; | 0 | ||||||||||||||||||||||||
553 | } | - | ||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||
555 | if (lastTokenWasAnAtom)
| 66-4144 | ||||||||||||||||||||||||
556 | m_delegate.quantifyAtom(min, max, !tryConsume('?')); executed 4143 times by 8 tests: m_delegate.quantifyAtom(min, max, !tryConsume('?')); Executed by:
| 4143 | ||||||||||||||||||||||||
557 | else | - | ||||||||||||||||||||||||
558 | m_err = QuantifierWithoutAtom; executed 66 times by 1 test: m_err = QuantifierWithoutAtom; Executed by:
| 66 | ||||||||||||||||||||||||
559 | } | - | ||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||
561 | /* | - | ||||||||||||||||||||||||
562 | * parseTokens(): | - | ||||||||||||||||||||||||
563 | * | - | ||||||||||||||||||||||||
564 | * This method loops over the input pattern reporting tokens to the delegate. | - | ||||||||||||||||||||||||
565 | * The method returns when a parse error is detected, or the end of the pattern | - | ||||||||||||||||||||||||
566 | * is reached. One piece of state is tracked around the loop, which is whether | - | ||||||||||||||||||||||||
567 | * the last token passed to the delegate was an atom (this is necessary to detect | - | ||||||||||||||||||||||||
568 | * a parse error when a quantifier provided without an atom to quantify). | - | ||||||||||||||||||||||||
569 | */ | - | ||||||||||||||||||||||||
570 | void parseTokens() | - | ||||||||||||||||||||||||
571 | { | - | ||||||||||||||||||||||||
572 | bool lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
573 | - | |||||||||||||||||||||||||
574 | while (!atEndOfPattern()) {
| 1150925-2386463 | ||||||||||||||||||||||||
575 | switch (peek()) { | - | ||||||||||||||||||||||||
576 | case '|': executed 1163 times by 4 tests: case '|': Executed by:
| 1163 | ||||||||||||||||||||||||
577 | consume(); | - | ||||||||||||||||||||||||
578 | m_delegate.disjunction(); | - | ||||||||||||||||||||||||
579 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
580 | break; executed 1164 times by 4 tests: break; Executed by:
| 1164 | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | case '(': executed 3574 times by 3 tests: case '(': Executed by:
| 3574 | ||||||||||||||||||||||||
583 | parseParenthesesBegin(); | - | ||||||||||||||||||||||||
584 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
585 | break; executed 3577 times by 3 tests: break; Executed by:
| 3577 | ||||||||||||||||||||||||
586 | - | |||||||||||||||||||||||||
587 | case ')': executed 3578 times by 3 tests: case ')': Executed by:
| 3578 | ||||||||||||||||||||||||
588 | parseParenthesesEnd(); | - | ||||||||||||||||||||||||
589 | lastTokenWasAnAtom = true; | - | ||||||||||||||||||||||||
590 | break; executed 3575 times by 3 tests: break; Executed by:
| 3575 | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | case '^': executed 180 times by 5 tests: case '^': Executed by:
| 180 | ||||||||||||||||||||||||
593 | consume(); | - | ||||||||||||||||||||||||
594 | m_delegate.assertionBOL(); | - | ||||||||||||||||||||||||
595 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
596 | break; executed 181 times by 5 tests: break; Executed by:
| 181 | ||||||||||||||||||||||||
597 | - | |||||||||||||||||||||||||
598 | case '$': executed 178 times by 5 tests: case '$': Executed by:
| 178 | ||||||||||||||||||||||||
599 | consume(); | - | ||||||||||||||||||||||||
600 | m_delegate.assertionEOL(); | - | ||||||||||||||||||||||||
601 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
602 | break; executed 178 times by 5 tests: break; Executed by:
| 178 | ||||||||||||||||||||||||
603 | - | |||||||||||||||||||||||||
604 | case '.': executed 627 times by 3 tests: case '.': Executed by:
| 627 | ||||||||||||||||||||||||
605 | consume(); | - | ||||||||||||||||||||||||
606 | m_delegate.atomBuiltInCharacterClass(NewlineClassID, true); | - | ||||||||||||||||||||||||
607 | lastTokenWasAnAtom = true; | - | ||||||||||||||||||||||||
608 | break; executed 626 times by 3 tests: break; Executed by:
| 626 | ||||||||||||||||||||||||
609 | - | |||||||||||||||||||||||||
610 | case '[': executed 3556 times by 6 tests: case '[': Executed by:
| 3556 | ||||||||||||||||||||||||
611 | parseCharacterClass(); | - | ||||||||||||||||||||||||
612 | lastTokenWasAnAtom = true; | - | ||||||||||||||||||||||||
613 | break; executed 3559 times by 6 tests: break; Executed by:
| 3559 | ||||||||||||||||||||||||
614 | - | |||||||||||||||||||||||||
615 | case '\\': executed 528641 times by 5 tests: case '\\': Executed by:
| 528641 | ||||||||||||||||||||||||
616 | lastTokenWasAnAtom = parseAtomEscape(); | - | ||||||||||||||||||||||||
617 | break; executed 528635 times by 5 tests: break; Executed by:
| 528635 | ||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||
619 | case '*': executed 2086 times by 3 tests: case '*': Executed by:
| 2086 | ||||||||||||||||||||||||
620 | consume(); | - | ||||||||||||||||||||||||
621 | parseQuantifier(lastTokenWasAnAtom, 0, quantifyInfinite); | - | ||||||||||||||||||||||||
622 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
623 | break; executed 2087 times by 3 tests: break; Executed by:
| 2087 | ||||||||||||||||||||||||
624 | - | |||||||||||||||||||||||||
625 | case '+': executed 958 times by 6 tests: case '+': Executed by:
| 958 | ||||||||||||||||||||||||
626 | consume(); | - | ||||||||||||||||||||||||
627 | parseQuantifier(lastTokenWasAnAtom, 1, quantifyInfinite); | - | ||||||||||||||||||||||||
628 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
629 | break; executed 957 times by 6 tests: break; Executed by:
| 957 | ||||||||||||||||||||||||
630 | - | |||||||||||||||||||||||||
631 | case '?': executed 718 times by 4 tests: case '?': Executed by:
| 718 | ||||||||||||||||||||||||
632 | consume(); | - | ||||||||||||||||||||||||
633 | parseQuantifier(lastTokenWasAnAtom, 0, 1); | - | ||||||||||||||||||||||||
634 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
635 | break; executed 718 times by 4 tests: break; Executed by:
| 718 | ||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||
637 | case '{': { executed 450 times by 3 tests: case '{': Executed by:
| 450 | ||||||||||||||||||||||||
638 | ParseState state = saveState(); | - | ||||||||||||||||||||||||
639 | - | |||||||||||||||||||||||||
640 | consume(); | - | ||||||||||||||||||||||||
641 | if (peekIsDigit()) {
| 0-450 | ||||||||||||||||||||||||
642 | unsigned min = consumeNumber(); | - | ||||||||||||||||||||||||
643 | unsigned max = min; | - | ||||||||||||||||||||||||
644 | - | |||||||||||||||||||||||||
645 | if (tryConsume(','))
| 154-298 | ||||||||||||||||||||||||
646 | max = peekIsDigit() ? consumeNumber() : quantifyInfinite; executed 154 times by 3 tests: max = peekIsDigit() ? consumeNumber() : quantifyInfinite; Executed by:
| 48-154 | ||||||||||||||||||||||||
647 | - | |||||||||||||||||||||||||
648 | if (tryConsume('}')) {
| 2-450 | ||||||||||||||||||||||||
649 | if (min <= max)
| 4-446 | ||||||||||||||||||||||||
650 | parseQuantifier(lastTokenWasAnAtom, min, max); executed 446 times by 3 tests: parseQuantifier(lastTokenWasAnAtom, min, max); Executed by:
| 446 | ||||||||||||||||||||||||
651 | else | - | ||||||||||||||||||||||||
652 | m_err = QuantifierOutOfOrder; executed 4 times by 1 test: m_err = QuantifierOutOfOrder; Executed by:
| 4 | ||||||||||||||||||||||||
653 | lastTokenWasAnAtom = false; | - | ||||||||||||||||||||||||
654 | break; executed 450 times by 3 tests: break; Executed by:
| 450 | ||||||||||||||||||||||||
655 | } | - | ||||||||||||||||||||||||
656 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||
658 | restoreState(state); | - | ||||||||||||||||||||||||
659 | } | - | ||||||||||||||||||||||||
660 | Q_FALLTHROUGH(); // if we did not find a complete quantifer, fall through to the default case. | - | ||||||||||||||||||||||||
661 | - | |||||||||||||||||||||||||
662 | default: code before this statement executed 2 times by 1 test: default: Executed by:
executed 1842410 times by 6 tests: default: Executed by:
| 2-1842410 | ||||||||||||||||||||||||
663 | m_delegate.atomPatternCharacter(consume()); | - | ||||||||||||||||||||||||
664 | lastTokenWasAnAtom = true; | - | ||||||||||||||||||||||||
665 | } executed 1843164 times by 6 tests: end of block Executed by:
| 1843164 | ||||||||||||||||||||||||
666 | - | |||||||||||||||||||||||||
667 | if (m_err)
| 252-2388738 | ||||||||||||||||||||||||
668 | return; executed 252 times by 1 test: return; Executed by:
| 252 | ||||||||||||||||||||||||
669 | } executed 2389130 times by 9 tests: end of block Executed by:
| 2389130 | ||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||
671 | if (m_parenthesesNestingDepth > 0)
| 0-1150894 | ||||||||||||||||||||||||
672 | m_err = MissingParentheses; never executed: m_err = MissingParentheses; | 0 | ||||||||||||||||||||||||
673 | } executed 1150738 times by 153 tests: end of block Executed by:
| 1150738 | ||||||||||||||||||||||||
674 | - | |||||||||||||||||||||||||
675 | /* | - | ||||||||||||||||||||||||
676 | * parse(): | - | ||||||||||||||||||||||||
677 | * | - | ||||||||||||||||||||||||
678 | * This method calls parseTokens() to parse over the input and converts any | - | ||||||||||||||||||||||||
679 | * error code to a const char* for a result. | - | ||||||||||||||||||||||||
680 | */ | - | ||||||||||||||||||||||||
681 | const char* parse() | - | ||||||||||||||||||||||||
682 | { | - | ||||||||||||||||||||||||
683 | if (m_size > MAX_PATTERN_SIZE)
| 0-1148700 | ||||||||||||||||||||||||
684 | m_err = PatternTooLarge; never executed: m_err = PatternTooLarge; | 0 | ||||||||||||||||||||||||
685 | else | - | ||||||||||||||||||||||||
686 | parseTokens(); executed 1148062 times by 153 tests: parseTokens(); Executed by:
| 1148062 | ||||||||||||||||||||||||
687 | ASSERT(atEndOfPattern() || m_err); | - | ||||||||||||||||||||||||
688 | - | |||||||||||||||||||||||||
689 | // The order of this array must match the ErrorCode enum. | - | ||||||||||||||||||||||||
690 | static const char* errorMessages[NumberOfErrorCodes] = { | - | ||||||||||||||||||||||||
691 | 0, // NoError | - | ||||||||||||||||||||||||
692 | REGEXP_ERROR_PREFIX "regular expression too large", | - | ||||||||||||||||||||||||
693 | REGEXP_ERROR_PREFIX "numbers out of order in {} quantifier", | - | ||||||||||||||||||||||||
694 | REGEXP_ERROR_PREFIX "nothing to repeat", | - | ||||||||||||||||||||||||
695 | REGEXP_ERROR_PREFIX "number too large in {} quantifier", | - | ||||||||||||||||||||||||
696 | REGEXP_ERROR_PREFIX "missing )", | - | ||||||||||||||||||||||||
697 | REGEXP_ERROR_PREFIX "unmatched parentheses", | - | ||||||||||||||||||||||||
698 | REGEXP_ERROR_PREFIX "unrecognized character after (?", | - | ||||||||||||||||||||||||
699 | REGEXP_ERROR_PREFIX "missing terminating ] for character class", | - | ||||||||||||||||||||||||
700 | REGEXP_ERROR_PREFIX "range out of order in character class", | - | ||||||||||||||||||||||||
701 | REGEXP_ERROR_PREFIX "\\ at end of pattern" | - | ||||||||||||||||||||||||
702 | }; | - | ||||||||||||||||||||||||
703 | - | |||||||||||||||||||||||||
704 | return errorMessages[m_err]; executed 1151300 times by 153 tests: return errorMessages[m_err]; Executed by:
| 1151300 | ||||||||||||||||||||||||
705 | } | - | ||||||||||||||||||||||||
706 | - | |||||||||||||||||||||||||
707 | // Misc helper functions: | - | ||||||||||||||||||||||||
708 | - | |||||||||||||||||||||||||
709 | typedef unsigned ParseState; | - | ||||||||||||||||||||||||
710 | - | |||||||||||||||||||||||||
711 | ParseState saveState() | - | ||||||||||||||||||||||||
712 | { | - | ||||||||||||||||||||||||
713 | return m_index; executed 2331 times by 3 tests: return m_index; Executed by:
| 2331 | ||||||||||||||||||||||||
714 | } | - | ||||||||||||||||||||||||
715 | - | |||||||||||||||||||||||||
716 | void restoreState(ParseState state) | - | ||||||||||||||||||||||||
717 | { | - | ||||||||||||||||||||||||
718 | m_index = state; | - | ||||||||||||||||||||||||
719 | } executed 98 times by 2 tests: end of block Executed by:
| 98 | ||||||||||||||||||||||||
720 | - | |||||||||||||||||||||||||
721 | bool atEndOfPattern() | - | ||||||||||||||||||||||||
722 | { | - | ||||||||||||||||||||||||
723 | ASSERT(m_index <= m_size); | - | ||||||||||||||||||||||||
724 | return m_index == m_size; executed 5254373 times by 153 tests: return m_index == m_size; Executed by:
| 5254373 | ||||||||||||||||||||||||
725 | } | - | ||||||||||||||||||||||||
726 | - | |||||||||||||||||||||||||
727 | int peek() | - | ||||||||||||||||||||||||
728 | { | - | ||||||||||||||||||||||||
729 | ASSERT(m_index < m_size); | - | ||||||||||||||||||||||||
730 | return m_data[m_index]; executed 3484021 times by 9 tests: return m_data[m_index]; Executed by:
| 3484021 | ||||||||||||||||||||||||
731 | } | - | ||||||||||||||||||||||||
732 | - | |||||||||||||||||||||||||
733 | bool peekIsDigit() | - | ||||||||||||||||||||||||
734 | { | - | ||||||||||||||||||||||||
735 | return !atEndOfPattern() && WTF::isASCIIDigit(peek()); executed 2519 times by 3 tests: return !atEndOfPattern() && WTF::isASCIIDigit(peek()); Executed by:
| 2519 | ||||||||||||||||||||||||
736 | } | - | ||||||||||||||||||||||||
737 | - | |||||||||||||||||||||||||
738 | unsigned peekDigit() | - | ||||||||||||||||||||||||
739 | { | - | ||||||||||||||||||||||||
740 | ASSERT(peekIsDigit()); | - | ||||||||||||||||||||||||
741 | return peek() - '0'; executed 28 times by 1 test: return peek() - '0'; Executed by:
| 28 | ||||||||||||||||||||||||
742 | } | - | ||||||||||||||||||||||||
743 | - | |||||||||||||||||||||||||
744 | int consume() | - | ||||||||||||||||||||||||
745 | { | - | ||||||||||||||||||||||||
746 | ASSERT(m_index < m_size); | - | ||||||||||||||||||||||||
747 | return m_data[m_index++]; executed 2942087 times by 9 tests: return m_data[m_index++]; Executed by:
| 2942087 | ||||||||||||||||||||||||
748 | } | - | ||||||||||||||||||||||||
749 | - | |||||||||||||||||||||||||
750 | unsigned consumeDigit() | - | ||||||||||||||||||||||||
751 | { | - | ||||||||||||||||||||||||
752 | ASSERT(peekIsDigit()); | - | ||||||||||||||||||||||||
753 | return consume() - '0'; executed 969 times by 3 tests: return consume() - '0'; Executed by:
| 969 | ||||||||||||||||||||||||
754 | } | - | ||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||
756 | unsigned consumeNumber() | - | ||||||||||||||||||||||||
757 | { | - | ||||||||||||||||||||||||
758 | unsigned n = consumeDigit(); | - | ||||||||||||||||||||||||
759 | // check for overflow. | - | ||||||||||||||||||||||||
760 | for (unsigned newValue; peekIsDigit() && ((newValue = n * 10 + peekDigit()) >= n); ) {
| 0-888 | ||||||||||||||||||||||||
761 | n = newValue; | - | ||||||||||||||||||||||||
762 | consume(); | - | ||||||||||||||||||||||||
763 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||||||||||||||
764 | return n; executed 890 times by 3 tests: return n; Executed by:
| 890 | ||||||||||||||||||||||||
765 | } | - | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | unsigned consumeOctal() | - | ||||||||||||||||||||||||
768 | { | - | ||||||||||||||||||||||||
769 | ASSERT(WTF::isASCIIOctalDigit(peek())); | - | ||||||||||||||||||||||||
770 | - | |||||||||||||||||||||||||
771 | unsigned n = consumeDigit(); | - | ||||||||||||||||||||||||
772 | while (n < 32 && !atEndOfPattern() && WTF::isASCIIOctalDigit(peek()))
| 0-80 | ||||||||||||||||||||||||
773 | n = n * 8 + consumeDigit(); executed 4 times by 1 test: n = n * 8 + consumeDigit(); Executed by:
| 4 | ||||||||||||||||||||||||
774 | return n; executed 76 times by 1 test: return n; Executed by:
| 76 | ||||||||||||||||||||||||
775 | } | - | ||||||||||||||||||||||||
776 | - | |||||||||||||||||||||||||
777 | bool tryConsume(UChar ch) | - | ||||||||||||||||||||||||
778 | { | - | ||||||||||||||||||||||||
779 | if (atEndOfPattern() || (m_data[m_index] != ch))
| 537-11637 | ||||||||||||||||||||||||
780 | return false; executed 9607 times by 9 tests: return false; Executed by:
| 9607 | ||||||||||||||||||||||||
781 | ++m_index; | - | ||||||||||||||||||||||||
782 | return true; executed 2569 times by 3 tests: return true; Executed by:
| 2569 | ||||||||||||||||||||||||
783 | } | - | ||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | int tryConsumeHex(int count) | - | ||||||||||||||||||||||||
786 | { | - | ||||||||||||||||||||||||
787 | ParseState state = saveState(); | - | ||||||||||||||||||||||||
788 | - | |||||||||||||||||||||||||
789 | int n = 0; | - | ||||||||||||||||||||||||
790 | while (count--) {
| 1312-3701 | ||||||||||||||||||||||||
791 | if (atEndOfPattern() || !WTF::isASCIIHexDigit(peek())) {
| 0-3688 | ||||||||||||||||||||||||
792 | restoreState(state); | - | ||||||||||||||||||||||||
793 | return -1; executed 16 times by 1 test: return -1; Executed by:
| 16 | ||||||||||||||||||||||||
794 | } | - | ||||||||||||||||||||||||
795 | n = (n << 4) | WTF::toASCIIHexValue(consume()); | - | ||||||||||||||||||||||||
796 | } executed 3686 times by 1 test: end of block Executed by:
| 3686 | ||||||||||||||||||||||||
797 | return n; executed 1312 times by 1 test: return n; Executed by:
| 1312 | ||||||||||||||||||||||||
798 | } | - | ||||||||||||||||||||||||
799 | - | |||||||||||||||||||||||||
800 | Delegate& m_delegate; | - | ||||||||||||||||||||||||
801 | unsigned m_backReferenceLimit; | - | ||||||||||||||||||||||||
802 | ErrorCode m_err; | - | ||||||||||||||||||||||||
803 | const CharType* m_data; | - | ||||||||||||||||||||||||
804 | unsigned m_size; | - | ||||||||||||||||||||||||
805 | unsigned m_index; | - | ||||||||||||||||||||||||
806 | unsigned m_parenthesesNestingDepth; | - | ||||||||||||||||||||||||
807 | - | |||||||||||||||||||||||||
808 | // Derived by empirical testing of compile time in PCRE and WREC. | - | ||||||||||||||||||||||||
809 | static const unsigned MAX_PATTERN_SIZE = 1024 * 1024; | - | ||||||||||||||||||||||||
810 | }; | - | ||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||
812 | /* | - | ||||||||||||||||||||||||
813 | * Yarr::parse(): | - | ||||||||||||||||||||||||
814 | * | - | ||||||||||||||||||||||||
815 | * The parse method is passed a pattern to be parsed and a delegate upon which | - | ||||||||||||||||||||||||
816 | * callbacks will be made to record the parsed tokens forming the regex. | - | ||||||||||||||||||||||||
817 | * Yarr::parse() returns null on success, or a const C string providing an error | - | ||||||||||||||||||||||||
818 | * message where a parse error occurs. | - | ||||||||||||||||||||||||
819 | * | - | ||||||||||||||||||||||||
820 | * The Delegate must implement the following interface: | - | ||||||||||||||||||||||||
821 | * | - | ||||||||||||||||||||||||
822 | * void assertionBOL(); | - | ||||||||||||||||||||||||
823 | * void assertionEOL(); | - | ||||||||||||||||||||||||
824 | * void assertionWordBoundary(bool invert); | - | ||||||||||||||||||||||||
825 | * | - | ||||||||||||||||||||||||
826 | * void atomPatternCharacter(UChar ch); | - | ||||||||||||||||||||||||
827 | * void atomBuiltInCharacterClass(BuiltInCharacterClassID classID, bool invert); | - | ||||||||||||||||||||||||
828 | * void atomCharacterClassBegin(bool invert) | - | ||||||||||||||||||||||||
829 | * void atomCharacterClassAtom(UChar ch) | - | ||||||||||||||||||||||||
830 | * void atomCharacterClassRange(UChar begin, UChar end) | - | ||||||||||||||||||||||||
831 | * void atomCharacterClassBuiltIn(BuiltInCharacterClassID classID, bool invert) | - | ||||||||||||||||||||||||
832 | * void atomCharacterClassEnd() | - | ||||||||||||||||||||||||
833 | * void atomParenthesesSubpatternBegin(bool capture = true); | - | ||||||||||||||||||||||||
834 | * void atomParentheticalAssertionBegin(bool invert = false); | - | ||||||||||||||||||||||||
835 | * void atomParenthesesEnd(); | - | ||||||||||||||||||||||||
836 | * void atomBackReference(unsigned subpatternId); | - | ||||||||||||||||||||||||
837 | * | - | ||||||||||||||||||||||||
838 | * void quantifyAtom(unsigned min, unsigned max, bool greedy); | - | ||||||||||||||||||||||||
839 | * | - | ||||||||||||||||||||||||
840 | * void disjunction(); | - | ||||||||||||||||||||||||
841 | * | - | ||||||||||||||||||||||||
842 | * The regular expression is described by a sequence of assertion*() and atom*() | - | ||||||||||||||||||||||||
843 | * callbacks to the delegate, describing the terms in the regular expression. | - | ||||||||||||||||||||||||
844 | * Following an atom a quantifyAtom() call may occur to indicate that the previous | - | ||||||||||||||||||||||||
845 | * atom should be quantified. In the case of atoms described across multiple | - | ||||||||||||||||||||||||
846 | * calls (parentheses and character classes) the call to quantifyAtom() will come | - | ||||||||||||||||||||||||
847 | * after the call to the atom*End() method, never after atom*Begin(). | - | ||||||||||||||||||||||||
848 | * | - | ||||||||||||||||||||||||
849 | * Character classes may either be described by a single call to | - | ||||||||||||||||||||||||
850 | * atomBuiltInCharacterClass(), or by a sequence of atomCharacterClass*() calls. | - | ||||||||||||||||||||||||
851 | * In the latter case, ...Begin() will be called, followed by a sequence of | - | ||||||||||||||||||||||||
852 | * calls to ...Atom(), ...Range(), and ...BuiltIn(), followed by a call to ...End(). | - | ||||||||||||||||||||||||
853 | * | - | ||||||||||||||||||||||||
854 | * Sequences of atoms and assertions are broken into alternatives via calls to | - | ||||||||||||||||||||||||
855 | * disjunction(). Assertions, atoms, and disjunctions emitted between calls to | - | ||||||||||||||||||||||||
856 | * atomParenthesesBegin() and atomParenthesesEnd() form the body of a subpattern. | - | ||||||||||||||||||||||||
857 | * atomParenthesesBegin() is passed a subpatternId. In the case of a regular | - | ||||||||||||||||||||||||
858 | * capturing subpattern, this will be the subpatternId associated with these | - | ||||||||||||||||||||||||
859 | * parentheses, and will also by definition be the lowest subpatternId of these | - | ||||||||||||||||||||||||
860 | * parentheses and of any nested paretheses. The atomParenthesesEnd() method | - | ||||||||||||||||||||||||
861 | * is passed the subpatternId of the last capturing subexpression nested within | - | ||||||||||||||||||||||||
862 | * these paretheses. In the case of a capturing subpattern with no nested | - | ||||||||||||||||||||||||
863 | * capturing subpatterns, the same subpatternId will be passed to the begin and | - | ||||||||||||||||||||||||
864 | * end functions. In the case of non-capturing subpatterns the subpatternId | - | ||||||||||||||||||||||||
865 | * passed to the begin method is also the first possible subpatternId that might | - | ||||||||||||||||||||||||
866 | * be nested within these paretheses. If a set of non-capturing parentheses does | - | ||||||||||||||||||||||||
867 | * not contain any capturing subpatterns, then the subpatternId passed to begin | - | ||||||||||||||||||||||||
868 | * will be greater than the subpatternId passed to end. | - | ||||||||||||||||||||||||
869 | */ | - | ||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||
871 | template<class Delegate> | - | ||||||||||||||||||||||||
872 | const char* parse(Delegate& delegate, const String& pattern, unsigned backReferenceLimit = quantifyInfinite) | - | ||||||||||||||||||||||||
873 | { | - | ||||||||||||||||||||||||
874 | if (pattern.is8Bit())
| 0-1148413 | ||||||||||||||||||||||||
875 | return Parser<Delegate, LChar>(delegate, pattern, backReferenceLimit).parse(); never executed: return Parser<Delegate, LChar>(delegate, pattern, backReferenceLimit).parse(); | 0 | ||||||||||||||||||||||||
876 | return Parser<Delegate, UChar>(delegate, pattern, backReferenceLimit).parse(); executed 1148419 times by 153 tests: return Parser<Delegate, UChar>(delegate, pattern, backReferenceLimit).parse(); Executed by:
| 1148419 | ||||||||||||||||||||||||
877 | } | - | ||||||||||||||||||||||||
878 | - | |||||||||||||||||||||||||
879 | } } // namespace JSC::Yarr | - | ||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||
881 | #endif // YarrParser_h | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |