Debian Codegraph @

src/regexp.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/regexp.c`/include "prism/regexp.h"cxx . . $ `<file>/include/prism/regexp.h`/
2
3 #define PM_REGEXP_PARSE_DEPTH_MAXcxx . . $ `src/regexp.c:3:9`! 4096
4
5 /**
6 * This is the parser that is going to handle parsing regular expressions.
7 */
8 typedef structcxx . . $ $anonymous_type_ee991db3e1ca1840_0# {
9 /** The parser that is currently being used. */
10 pm_parser_tcxx . . $ pm_parser_t# *parsercxx . . $ $anonymous_type_ee991db3e1ca1840_0#parser.;
11
12 /** A pointer to the start of the source that we are parsing. */
13 const uint8_tcxx . . $ uint8_t# *startcxx . . $ $anonymous_type_ee991db3e1ca1840_0#start.;
14
15 /** A pointer to the current position in the source. */
16 const uint8_tcxx . . $ uint8_t# *cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.;
17
18 /** A pointer to the end of the source that we are parsing. */
19 const uint8_tcxx . . $ uint8_t# *endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.;
20
21 /**
22 * Whether or not the regular expression currently being parsed is in
23 * extended mode, wherein whitespace is ignored and comments are allowed.
24 */
25 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode.;
26
27 /** Whether the encoding has changed from the default. */
28 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! encoding_changedcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding_changed.;
29
30 /** The encoding of the source. */
31 const pm_encoding_tcxx . . $ pm_encoding_t# *encodingcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding.;
32
33 /** The callback to call when a named capture group is found. */
34 pm_regexp_name_callback_tcxx . . $ pm_regexp_name_callback_t# name_callbackcxx . . $ $anonymous_type_ee991db3e1ca1840_0#name_callback.;
35
36 /** The data to pass to the name callback. */
37 void *name_datacxx . . $ $anonymous_type_ee991db3e1ca1840_0#name_data.;
38
39 /** The callback to call when a parse error is found. */
40 pm_regexp_error_callback_tcxx . . $ pm_regexp_error_callback_t# error_callbackcxx . . $ $anonymous_type_ee991db3e1ca1840_0#error_callback.;
41
42 /** The data to pass to the error callback. */
43 void *error_datacxx . . $ $anonymous_type_ee991db3e1ca1840_0#error_data.;
44 } pm_regexp_parser_tcxx . . $ pm_regexp_parser_t#;
45
46 /**
47 * Append an error to the parser.
48 */
49 static inline void
50 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, const uint8_tcxx . . $ uint8_t# *start, const uint8_tcxx . . $ uint8_t# *end, const char *message) {
51 parser->error_callbackcxx . . $ $anonymous_type_ee991db3e1ca1840_0#error_callback.(start, end, message, parser->error_datacxx . . $ $anonymous_type_ee991db3e1ca1840_0#error_data.);
52 }
53
54 /**
55 * This appends a new string to the list of named captures. This function
56 * assumes the caller has already checked the validity of the name callback.
57 */
58 static void
59 pm_regexp_parser_named_capturecxx . . $ pm_regexp_parser_named_capture(67e479532431c1e8).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, const uint8_tcxx . . $ uint8_t# *start, const uint8_tcxx . . $ uint8_t# *end) {
60 pm_string_tcxx . . $ pm_string_t# string;
61 pm_string_shared_initcxx . . $ pm_string_shared_init(3931a8f5f74a1622).(&string, start, end);
62 parser->name_callbackcxx . . $ $anonymous_type_ee991db3e1ca1840_0#name_callback.(&string, parser->name_datacxx . . $ $anonymous_type_ee991db3e1ca1840_0#name_data.);
63 pm_string_freecxx . . $ pm_string_free(c15d128c68b0cb72).(&string);
64 }
65
66 /**
67 * Returns true if the next character is the end of the source.
68 */
69 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
70 pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser) {
71 return parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. >= parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.;
72 }
73
74 /**
75 * Optionally accept a char and consume it if it exists.
76 */
77 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
78 pm_regexp_char_acceptcxx . . $ pm_regexp_char_accept(185947678735c76d).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint8_tcxx . . $ uint8_t# value) {
79 if (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. == value) {
80 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
81 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
82 }
83 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
84 }
85
86 /**
87 * Expect a character to be present and consume it.
88 */
89 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
90 pm_regexp_char_expectcxx . . $ pm_regexp_char_expect(185947678735c76d).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint8_tcxx . . $ uint8_t# value) {
91 if (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. == value) {
92 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
93 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
94 }
95 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
96 }
97
98 /**
99 * This advances the current token to the next instance of the given character.
100 */
101 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
102 pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint8_tcxx . . $ uint8_t# value) {
103 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
104 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
105 }
106
107 const uint8_tcxx . . $ uint8_t# *end = (const uint8_tcxx . . $ uint8_t# *) pm_memchrcxx . . $ pm_memchr(fccc166115c7ad11).(parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., value, (size_t) (parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end. - parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.), parser->encoding_changedcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding_changed., parser->encodingcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding.);
108 if (end == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
109 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
110 }
111
112 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = end + 1;
113 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
114 }
115
116 /**
117 * Range quantifiers are a special class of quantifiers that look like
118 *
119 * * {digit}
120 * * {digit,}
121 * * {digit,digit}
122 * * {,digit}
123 *
124 * Unfortunately, if there are any spaces in between, then this just becomes a
125 * regular character match expression and we have to backtrack. So when this
126 * function first starts running, we'll create a "save" point and then attempt
127 * to parse the quantifier. If it fails, we'll restore the save point and
128 * return.
129 *
130 * The properly track everything, we're going to build a little state machine.
131 * It looks something like the following:
132 *
133 * +-------+ +---------+ ------------+
134 * ---- lbrace ---> | start | ---- digit ---> | minimum | |
135 * +-------+ +---------+ <--- digit -+
136 * | | |
137 * +-------+ | | rbrace
138 * | comma | <----- comma +---- comma -------+ |
139 * +-------+ V V
140 * | +---------+ +---------+
141 * +-- digit --> | maximum | -- rbrace --> || final ||
142 * +---------+ +---------+
143 * | ^
144 * +- digit -+
145 *
146 * Note that by the time we've hit this function, the lbrace has already been
147 * consumed so we're in the start state.
148 */
149 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
150 pm_regexp_parse_range_quantifiercxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser) {
151 const uint8_tcxx . . $ uint8_t# *savepoint = parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.;
152
153 enumcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).$anonymous_type_1# {
154 PM_REGEXP_RANGE_QUANTIFIER_STATE_STARTcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_START.,
155 PM_REGEXP_RANGE_QUANTIFIER_STATE_MINIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MINIMUM.,
156 PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUM.,
157 PM_REGEXP_RANGE_QUANTIFIER_STATE_COMMAcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_COMMA.
158 } state = PM_REGEXP_RANGE_QUANTIFIER_STATE_STARTcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_START.;
159
160 while (1) {
161 if (parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. >= parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.) {
162 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = savepoint;
163 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
164 }
165
166 switch (state) {
167 case PM_REGEXP_RANGE_QUANTIFIER_STATE_STARTcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_START.:
168 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
169 case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
170 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
171 state = PM_REGEXP_RANGE_QUANTIFIER_STATE_MINIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MINIMUM.;
172 break;
173 case ',':
174 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
175 state = PM_REGEXP_RANGE_QUANTIFIER_STATE_COMMAcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_COMMA.;
176 break;
177 default:
178 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = savepoint;
179 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
180 }
181 break;
182 case PM_REGEXP_RANGE_QUANTIFIER_STATE_MINIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MINIMUM.:
183 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
184 case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
185 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
186 break;
187 case ',':
188 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
189 state = PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUM.;
190 break;
191 case '}':
192 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
193 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
194 default:
195 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = savepoint;
196 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
197 }
198 break;
199 case PM_REGEXP_RANGE_QUANTIFIER_STATE_COMMAcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_COMMA.:
200 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
201 case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
202 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
203 state = PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUM.;
204 break;
205 default:
206 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = savepoint;
207 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
208 }
209 break;
210 case PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUMcxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).PM_REGEXP_RANGE_QUANTIFIER_STATE_MAXIMUM.:
211 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
212 case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
213 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
214 break;
215 case '}':
216 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
217 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
218 default:
219 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = savepoint;
220 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
221 }
222 break;
223 }
224 }
225
226 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
227 }
228
229 /**
230 * quantifier : star-quantifier
231 * | plus-quantifier
232 * | optional-quantifier
233 * | range-quantifier
234 * | <empty>
235 * ;
236 */
237 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
238 pm_regexp_parse_quantifiercxx . . $ pm_regexp_parse_quantifier(dfbfae072bfcb996).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser) {
239 while (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
240 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
241 case '*':
242 case '+':
243 case '?':
244 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
245 break;
246 case '{':
247 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
248 if (!pm_regexp_parse_range_quantifiercxx . . $ pm_regexp_parse_range_quantifier(dfbfae072bfcb996).(parser)) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
249 break;
250 default:
251 // In this case there is no quantifier.
252 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
253 }
254 }
255
256 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
257 }
258
259 /**
260 * match-posix-class : '[' '[' ':' '^'? CHAR+ ':' ']' ']'
261 * ;
262 */
263 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
264 pm_regexp_parse_posix_classcxx . . $ pm_regexp_parse_posix_class(dfbfae072bfcb996).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser) {
265 if (!pm_regexp_char_expectcxx . . $ pm_regexp_char_expect(185947678735c76d).(parser, ':')) {
266 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
267 }
268
269 pm_regexp_char_acceptcxx . . $ pm_regexp_char_accept(185947678735c76d).(parser, '^');
270
271 return (
272 pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, ':') &&
273 pm_regexp_char_expectcxx . . $ pm_regexp_char_expect(185947678735c76d).(parser, ']') &&
274 pm_regexp_char_expectcxx . . $ pm_regexp_char_expect(185947678735c76d).(parser, ']')
275 );
276 }
277
278 // Forward declaration because character sets can be nested.
279 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
280 pm_regexp_parse_lbracketcxx . . $ pm_regexp_parse_lbracket(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth);
281
282 /**
283 * match-char-set : '[' '^'? (match-range | match-char)* ']'
284 * ;
285 */
286 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
287 pm_regexp_parse_character_setcxx . . $ pm_regexp_parse_character_set(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth) {
288 pm_regexp_char_acceptcxx . . $ pm_regexp_char_accept(185947678735c76d).(parser, '^');
289
290 while (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ']') {
291 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++) {
292 case '[':
293 pm_regexp_parse_lbracketcxx . . $ pm_regexp_parse_lbracket(6d92fd84c3693b58).(parser, (uint16_tcxx . . $ uint16_t#) (depth + 1));
294 break;
295 case '\\':
296 if (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
297 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
298 }
299 break;
300 default:
301 // do nothing, we've already advanced the cursor
302 break;
303 }
304 }
305
306 return pm_regexp_char_expectcxx . . $ pm_regexp_char_expect(185947678735c76d).(parser, ']');
307 }
308
309 /**
310 * A left bracket can either mean a POSIX class or a character set.
311 */
312 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
313 pm_regexp_parse_lbracketcxx . . $ pm_regexp_parse_lbracket(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth) {
314 if (depth >= PM_REGEXP_PARSE_DEPTH_MAXcxx . . $ `src/regexp.c:3:9`!) {
315 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, parser->startcxx . . $ $anonymous_type_ee991db3e1ca1840_0#start., parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end., "parse depth limit over");
316 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
317 }
318
319 if ((parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. < parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.) && parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.[0] == ']') {
320 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
321 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 1, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "empty char-class");
322 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
323 }
324
325 const uint8_tcxx . . $ uint8_t# *reset = parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.;
326
327 if ((parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. + 2 < parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.) && parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.[0] == '[' && parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.[1] == ':') {
328 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
329 if (pm_regexp_parse_posix_classcxx . . $ pm_regexp_parse_posix_class(dfbfae072bfcb996).(parser)) return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
330
331 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = reset;
332 }
333
334 return pm_regexp_parse_character_setcxx . . $ pm_regexp_parse_character_set(6d92fd84c3693b58).(parser, depth);
335 }
336
337 // Forward declaration here since parsing groups needs to go back up the grammar
338 // to parse expressions within them.
339 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
340 pm_regexp_parse_expressioncxx . . $ pm_regexp_parse_expression(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth);
341
342 /**
343 * These are the states of the options that are configurable on the regular
344 * expression (or from within a group).
345 */
346 typedef enumcxx . . $ $anonymous_type_ee991db3e1ca1840_2# {
347 PM_REGEXP_OPTION_STATE_INVALIDcxx . . $ PM_REGEXP_OPTION_STATE_INVALID.,
348 PM_REGEXP_OPTION_STATE_TOGGLEABLEcxx . . $ PM_REGEXP_OPTION_STATE_TOGGLEABLE.,
349 PM_REGEXP_OPTION_STATE_ADDABLEcxx . . $ PM_REGEXP_OPTION_STATE_ADDABLE.,
350 PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.,
351 PM_REGEXP_OPTION_STATE_REMOVEDcxx . . $ PM_REGEXP_OPTION_STATE_REMOVED.
352 } pm_regexp_option_state_tcxx . . $ pm_regexp_option_state_t#;
353
354 // These are the options that are configurable on the regular expression (or
355 // from within a group).
356
357 #define PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`! 'a'
358 #define PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUMcxx . . $ `src/regexp.c:358:9`! 'x'
359 #define PRISM_REGEXP_OPTION_STATE_SLOTScxx . . $ `src/regexp.c:359:9`! (PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUMcxx . . $ `src/regexp.c:358:9`! - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`! + 1)
360
361 /**
362 * This is the set of options that are configurable on the regular expression.
363 */
364 typedef structcxx . . $ $anonymous_type_ee991db3e1ca1840_3# {
365 /** The current state of each option. */
366 uint8_tcxx . . $ uint8_t# valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.[PRISM_REGEXP_OPTION_STATE_SLOTScxx . . $ `src/regexp.c:359:9`!];
367 } pm_regexp_options_tcxx . . $ pm_regexp_options_t#;
368
369 /**
370 * Initialize a new set of options to their default values.
371 */
372 static void
373 pm_regexp_options_initcxx . . $ pm_regexp_options_init(3b56284dc2bdaa72).(pm_regexp_options_tcxx . . $ pm_regexp_options_t# *options) {
374 memsetcxx . . $ memset(d1de1e4fb215f1c6).(options, PM_REGEXP_OPTION_STATE_INVALIDcxx . . $ PM_REGEXP_OPTION_STATE_INVALID., sizeof(uint8_tcxx . . $ uint8_t#) * PRISM_REGEXP_OPTION_STATE_SLOTScxx . . $ `src/regexp.c:359:9`!);
375 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.['i' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!] = PM_REGEXP_OPTION_STATE_TOGGLEABLEcxx . . $ PM_REGEXP_OPTION_STATE_TOGGLEABLE.;
376 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.['m' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!] = PM_REGEXP_OPTION_STATE_TOGGLEABLEcxx . . $ PM_REGEXP_OPTION_STATE_TOGGLEABLE.;
377 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.['x' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!] = PM_REGEXP_OPTION_STATE_TOGGLEABLEcxx . . $ PM_REGEXP_OPTION_STATE_TOGGLEABLE.;
378 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.['d' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!] = PM_REGEXP_OPTION_STATE_ADDABLEcxx . . $ PM_REGEXP_OPTION_STATE_ADDABLE.;
379 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.['a' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!] = PM_REGEXP_OPTION_STATE_ADDABLEcxx . . $ PM_REGEXP_OPTION_STATE_ADDABLE.;
380 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.['u' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!] = PM_REGEXP_OPTION_STATE_ADDABLEcxx . . $ PM_REGEXP_OPTION_STATE_ADDABLE.;
381 }
382
383 /**
384 * Attempt to add the given option to the set of options. Returns true if it was
385 * added, false if it was already present.
386 */
387 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
388 pm_regexp_options_addcxx . . $ pm_regexp_options_add(528ccb8f4f243f92).(pm_regexp_options_tcxx . . $ pm_regexp_options_t# *options, uint8_tcxx . . $ uint8_t# key) {
389 if (key >= PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`! && key <= PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUMcxx . . $ `src/regexp.c:358:9`!) {
390 key = (uint8_tcxx . . $ uint8_t#) (key - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!);
391
392 switch (options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.[key]) {
393 case PM_REGEXP_OPTION_STATE_INVALIDcxx . . $ PM_REGEXP_OPTION_STATE_INVALID.:
394 case PM_REGEXP_OPTION_STATE_REMOVEDcxx . . $ PM_REGEXP_OPTION_STATE_REMOVED.:
395 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
396 case PM_REGEXP_OPTION_STATE_TOGGLEABLEcxx . . $ PM_REGEXP_OPTION_STATE_TOGGLEABLE.:
397 case PM_REGEXP_OPTION_STATE_ADDABLEcxx . . $ PM_REGEXP_OPTION_STATE_ADDABLE.:
398 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.[key] = PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.;
399 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
400 case PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.:
401 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
402 }
403 }
404
405 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
406 }
407
408 /**
409 * Attempt to remove the given option from the set of options. Returns true if
410 * it was removed, false if it was already absent.
411 */
412 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
413 pm_regexp_options_removecxx . . $ pm_regexp_options_remove(528ccb8f4f243f92).(pm_regexp_options_tcxx . . $ pm_regexp_options_t# *options, uint8_tcxx . . $ uint8_t# key) {
414 if (key >= PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`! && key <= PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUMcxx . . $ `src/regexp.c:358:9`!) {
415 key = (uint8_tcxx . . $ uint8_t#) (key - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!);
416
417 switch (options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.[key]) {
418 case PM_REGEXP_OPTION_STATE_INVALIDcxx . . $ PM_REGEXP_OPTION_STATE_INVALID.:
419 case PM_REGEXP_OPTION_STATE_ADDABLEcxx . . $ PM_REGEXP_OPTION_STATE_ADDABLE.:
420 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
421 case PM_REGEXP_OPTION_STATE_TOGGLEABLEcxx . . $ PM_REGEXP_OPTION_STATE_TOGGLEABLE.:
422 case PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.:
423 case PM_REGEXP_OPTION_STATE_REMOVEDcxx . . $ PM_REGEXP_OPTION_STATE_REMOVED.:
424 options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.[key] = PM_REGEXP_OPTION_STATE_REMOVEDcxx . . $ PM_REGEXP_OPTION_STATE_REMOVED.;
425 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
426 }
427 }
428
429 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
430 }
431
432 /**
433 * True if the given key is set in the options.
434 */
435 static uint8_tcxx . . $ uint8_t#
436 pm_regexp_options_statecxx . . $ pm_regexp_options_state(b016610dfc233e2a).(pm_regexp_options_tcxx . . $ pm_regexp_options_t# *options, uint8_tcxx . . $ uint8_t# key) {
437 if (key >= PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`! && key <= PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUMcxx . . $ `src/regexp.c:358:9`!) {
438 key = (uint8_tcxx . . $ uint8_t#) (key - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUMcxx . . $ `src/regexp.c:357:9`!);
439 return options->valuescxx . . $ $anonymous_type_ee991db3e1ca1840_3#values.[key];
440 }
441
442 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
443 }
444
445 /**
446 * Groups can have quite a few different patterns for syntax. They basically
447 * just wrap a set of expressions, but they can potentially have options after a
448 * question mark. If there _isn't_ a question mark, then it's just a set of
449 * expressions. If there _is_, then here are the options:
450 *
451 * * (?#...) - inline comments
452 * * (?:subexp) - non-capturing group
453 * * (?=subexp) - positive lookahead
454 * * (?!subexp) - negative lookahead
455 * * (?>subexp) - atomic group
456 * * (?~subexp) - absence operator
457 * * (?<=subexp) - positive lookbehind
458 * * (?<!subexp) - negative lookbehind
459 * * (?<name>subexp) - named capturing group
460 * * (?'name'subexp) - named capturing group
461 * * (?(cond)yes-subexp) - conditional expression
462 * * (?(cond)yes-subexp|no-subexp) - conditional expression
463 * * (?imxdau-imx) - turn on and off configuration
464 * * (?imxdau-imx:subexp) - turn on and off configuration for an expression
465 */
466 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
467 pm_regexp_parse_groupcxx . . $ pm_regexp_parse_group(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth) {
468 const uint8_tcxx . . $ uint8_t# *group_start = parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.;
469
470 pm_regexp_options_tcxx . . $ pm_regexp_options_t# options;
471 pm_regexp_options_initcxx . . $ pm_regexp_options_init(3b56284dc2bdaa72).(&options);
472
473 // First, parse any options for the group.
474 if (pm_regexp_char_acceptcxx . . $ pm_regexp_char_accept(185947678735c76d).(parser, '?')) {
475 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
476 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, group_start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "end pattern in group");
477 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
478 }
479
480 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
481 case '#': { // inline comments
482 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
483 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
484 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, group_start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "end pattern in group");
485 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
486 }
487
488 if (parser->encoding_changedcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding_changed. && parser->encodingcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding.->multibytecxx . . $ $anonymous_type_f1726b61bf0350fa_0#multibyte.) {
489 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! escaped = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
490
491 // Here we're going to take a slow path and iterate through
492 // each multibyte character to find the close paren. We do
493 // this because \ can be a trailing byte in some encodings.
494 while (parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. < parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.) {
495 if (!escaped && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. == ')') {
496 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
497 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
498 }
499
500 size_t width = parser->encodingcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding.->char_widthcxx . . $ $anonymous_type_f1726b61bf0350fa_0#char_width.(parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., (ptrdiff_t) (parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end. - parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.));
501 if (width == 0) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
502
503 escaped = (width == 1) && (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. == '\\');
504 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. += width;
505 }
506
507 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
508 } else {
509 // Here we can take the fast path and use memchr to find the
510 // next ) because we are safe checking backward for \ since
511 // it cannot be a trailing character.
512 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! found = pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, ')');
513
514 while (found && (parser->startcxx . . $ $anonymous_type_ee991db3e1ca1840_0#start. <= parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 2) && (*(parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 2) == '\\')) {
515 found = pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, ')');
516 }
517
518 return found;
519 }
520 }
521 case ':': // non-capturing group
522 case '=': // positive lookahead
523 case '!': // negative lookahead
524 case '>': // atomic group
525 case '~': // absence operator
526 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
527 break;
528 case '<':
529 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
530 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
531 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, group_start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "end pattern with unmatched parenthesis");
532 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
533 }
534
535 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
536 case '=': // positive lookbehind
537 case '!': // negative lookbehind
538 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
539 break;
540 default: { // named capture group
541 const uint8_tcxx . . $ uint8_t# *start = parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.;
542 if (!pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, '>')) {
543 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
544 }
545
546 if (parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - start == 1) {
547 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "group name is empty");
548 }
549
550 if (parser->name_callbackcxx . . $ $anonymous_type_ee991db3e1ca1840_0#name_callback. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
551 pm_regexp_parser_named_capturecxx . . $ pm_regexp_parser_named_capture(67e479532431c1e8).(parser, start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 1);
552 }
553
554 break;
555 }
556 }
557 break;
558 case '\'': { // named capture group
559 const uint8_tcxx . . $ uint8_t# *start = ++parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.;
560 if (!pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, '\'')) {
561 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
562 }
563
564 if (parser->name_callbackcxx . . $ $anonymous_type_ee991db3e1ca1840_0#name_callback. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
565 pm_regexp_parser_named_capturecxx . . $ pm_regexp_parser_named_capture(67e479532431c1e8).(parser, start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 1);
566 }
567
568 break;
569 }
570 case '(': // conditional expression
571 if (!pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, ')')) {
572 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
573 }
574 break;
575 case 'i': case 'm': case 'x': case 'd': case 'a': case 'u': // options
576 while (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != '-' && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ':' && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ')') {
577 if (!pm_regexp_options_addcxx . . $ pm_regexp_options_add(528ccb8f4f243f92).(&options, *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.)) {
578 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
579 }
580 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
581 }
582
583 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
584 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
585 }
586
587 // If we are at the end of the group of options and there is no
588 // subexpression, then we are going to be setting the options
589 // for the parent group. In this case we are safe to return now.
590 if (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. == ')') {
591 if (pm_regexp_options_statecxx . . $ pm_regexp_options_state(b016610dfc233e2a).(&options, 'x') == PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.) {
592 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
593 }
594
595 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
596 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
597 }
598
599 // If we hit a -, then we're done parsing options.
600 if (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != '-') break;
601
602 PRISM_FALLTHROUGHcxx . . $ `include/prism/defines.h:253:13`!
603 case '-':
604 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
605 while (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ':' && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ')') {
606 if (!pm_regexp_options_removecxx . . $ pm_regexp_options_remove(528ccb8f4f243f92).(&options, *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.)) {
607 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
608 }
609 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
610 }
611
612 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
613 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
614 }
615
616 // If we are at the end of the group of options and there is no
617 // subexpression, then we are going to be setting the options
618 // for the parent group. In this case we are safe to return now.
619 if (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. == ')') {
620 switch (pm_regexp_options_statecxx . . $ pm_regexp_options_state(b016610dfc233e2a).(&options, 'x')) {
621 case PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.:
622 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
623 break;
624 case PM_REGEXP_OPTION_STATE_REMOVEDcxx . . $ PM_REGEXP_OPTION_STATE_REMOVED.:
625 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
626 break;
627 }
628
629 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
630 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
631 }
632
633 break;
634 default:
635 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
636 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 1, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "undefined group option");
637 break;
638 }
639 }
640
641 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! extended_mode = parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode.;
642 switch (pm_regexp_options_statecxx . . $ pm_regexp_options_state(b016610dfc233e2a).(&options, 'x')) {
643 case PM_REGEXP_OPTION_STATE_ADDEDcxx . . $ PM_REGEXP_OPTION_STATE_ADDED.:
644 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
645 break;
646 case PM_REGEXP_OPTION_STATE_REMOVEDcxx . . $ PM_REGEXP_OPTION_STATE_REMOVED.:
647 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
648 break;
649 }
650
651 // Now, parse the expressions within this group.
652 while (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ')') {
653 if (!pm_regexp_parse_expressioncxx . . $ pm_regexp_parse_expression(6d92fd84c3693b58).(parser, (uint16_tcxx . . $ uint16_t#) (depth + 1))) {
654 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = extended_mode;
655 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
656 }
657 pm_regexp_char_acceptcxx . . $ pm_regexp_char_accept(185947678735c76d).(parser, '|');
658 }
659
660 // Finally, make sure we have a closing parenthesis.
661 parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode. = extended_mode;
662 if (pm_regexp_char_expectcxx . . $ pm_regexp_char_expect(185947678735c76d).(parser, ')')) return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
663
664 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, group_start, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "end pattern with unmatched parenthesis");
665 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
666 }
667
668 /**
669 * item : anchor
670 * | match-posix-class
671 * | match-char-set
672 * | match-char-class
673 * | match-char-prop
674 * | match-char
675 * | match-any
676 * | group
677 * | quantified
678 * ;
679 */
680 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
681 pm_regexp_parse_itemcxx . . $ pm_regexp_parse_item(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth) {
682 switch (*parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.) {
683 case '^':
684 case '$':
685 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
686 return pm_regexp_parse_quantifiercxx . . $ pm_regexp_parse_quantifier(dfbfae072bfcb996).(parser);
687 case '\\':
688 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
689 if (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) {
690 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
691 }
692 return pm_regexp_parse_quantifiercxx . . $ pm_regexp_parse_quantifier(dfbfae072bfcb996).(parser);
693 case '(':
694 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
695 return pm_regexp_parse_groupcxx . . $ pm_regexp_parse_group(6d92fd84c3693b58).(parser, depth) && pm_regexp_parse_quantifiercxx . . $ pm_regexp_parse_quantifier(dfbfae072bfcb996).(parser);
696 case '[':
697 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
698 return pm_regexp_parse_lbracketcxx . . $ pm_regexp_parse_lbracket(6d92fd84c3693b58).(parser, depth) && pm_regexp_parse_quantifiercxx . . $ pm_regexp_parse_quantifier(dfbfae072bfcb996).(parser);
699 case '*':
700 case '?':
701 case '+':
702 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
703 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 1, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "target of repeat operator is not specified");
704 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
705 case ')':
706 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.++;
707 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. - 1, parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., "unmatched close parenthesis");
708 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
709 case '#':
710 if (parser->extended_modecxx . . $ $anonymous_type_ee991db3e1ca1840_0#extended_mode.) {
711 if (!pm_regexp_char_findcxx . . $ pm_regexp_char_find(185947678735c76d).(parser, '\n')) parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. = parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end.;
712 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
713 }
714 PRISM_FALLTHROUGHcxx . . $ `include/prism/defines.h:253:13`!
715 default: {
716 size_t width;
717 if (!parser->encoding_changedcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding_changed.) {
718 width = pm_encoding_utf_8_char_widthcxx . . $ pm_encoding_utf_8_char_width(dc9dc2cf7fc514b1).(parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., (ptrdiff_t) (parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end. - parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.));
719 } else {
720 width = parser->encodingcxx . . $ $anonymous_type_ee991db3e1ca1840_0#encoding.->char_widthcxx . . $ $anonymous_type_f1726b61bf0350fa_0#char_width.(parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor., (ptrdiff_t) (parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end. - parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor.));
721 }
722
723 if (width == 0) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; // TODO: add appropriate error
724 parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. += width;
725
726 return pm_regexp_parse_quantifiercxx . . $ pm_regexp_parse_quantifier(dfbfae072bfcb996).(parser);
727 }
728 }
729 }
730
731 /**
732 * expression : item+
733 * ;
734 */
735 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
736 pm_regexp_parse_expressioncxx . . $ pm_regexp_parse_expression(6d92fd84c3693b58).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser, uint16_tcxx . . $ uint16_t# depth) {
737 if (depth >= PM_REGEXP_PARSE_DEPTH_MAXcxx . . $ `src/regexp.c:3:9`!) {
738 pm_regexp_parse_errorcxx . . $ pm_regexp_parse_error(10afe0e5414acb58).(parser, parser->startcxx . . $ $anonymous_type_ee991db3e1ca1840_0#start., parser->endcxx . . $ $anonymous_type_ee991db3e1ca1840_0#end., "parse depth limit over");
739 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
740 }
741
742 if (!pm_regexp_parse_itemcxx . . $ pm_regexp_parse_item(6d92fd84c3693b58).(parser, depth)) {
743 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
744 }
745
746 while (!pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser) && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != ')' && *parser->cursorcxx . . $ $anonymous_type_ee991db3e1ca1840_0#cursor. != '|') {
747 if (!pm_regexp_parse_itemcxx . . $ pm_regexp_parse_item(6d92fd84c3693b58).(parser, depth)) {
748 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
749 }
750 }
751
752 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
753 }
754
755 /**
756 * pattern : EOF
757 * | expression EOF
758 * | expression '|' pattern
759 * ;
760 */
761 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
762 pm_regexp_parse_patterncxx . . $ pm_regexp_parse_pattern(dfbfae072bfcb996).(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t# *parser) {
763 do {
764 if (pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser)) return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
765 if (!pm_regexp_parse_expressioncxx . . $ pm_regexp_parse_expression(6d92fd84c3693b58).(parser, 0)) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
766 } while (pm_regexp_char_acceptcxx . . $ pm_regexp_char_accept(185947678735c76d).(parser, '|'));
767
768 return pm_regexp_char_is_eofcxx . . $ pm_regexp_char_is_eof(dfbfae072bfcb996).(parser);
769 }
770
771 /**
772 * Parse a regular expression and extract the names of all of the named capture
773 * groups.
774 */
775 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
776 pm_regexp_parsecxx . . $ pm_regexp_parse(18f18c3cfbfe72ea).(pm_parser_tcxx . . $ pm_parser_t# *parser, const uint8_tcxx . . $ uint8_t# *source, size_t size, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! extended_mode, pm_regexp_name_callback_tcxx . . $ pm_regexp_name_callback_t# name_callback, void *name_data, pm_regexp_error_callback_tcxx . . $ pm_regexp_error_callback_t# error_callback, void *error_data) {
777 pm_regexp_parse_patterncxx . . $ pm_regexp_parse_pattern(dfbfae072bfcb996).(&(pm_regexp_parser_tcxx . . $ pm_regexp_parser_t#) {
778 .parser = parser,
779 .start = source,
780 .cursor = source,
781 .end = source + size,
782 .extended_mode = extended_mode,
783 .encoding_changed = parser->encoding_changedcxx . . $ pm_parser#encoding_changed.,
784 .encoding = parser->encodingcxx . . $ pm_parser#encoding.,
785 .name_callback = name_callback,
786 .name_data = name_data,
787 .error_callback = error_callback,
788 .error_data = error_data
789 });
790 }