blob: 73af3cad5db7a81ed0035c8d52164a2cd27af61b [file] [log] [blame]
Guido van Rossum51b3aa31997-10-06 14:43:11 +00001/***********************************************************
2Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
29
30******************************************************************/
31
32/* Pcre objects */
33
34#include "Python.h"
35
36#ifndef Py_eval_input
37/* For Python 1.4, graminit.h has to be explicitly included */
38#include "graminit.h"
39#define Py_eval_input eval_input
40#endif
41
42#ifndef FOR_PYTHON
43#define FOR_PYTHON
44#endif
45
46#include "pcre.h"
47#include "pcre-internal.h"
48
49static PyObject *ErrorObject;
50
51typedef struct {
52 PyObject_HEAD
53 pcre *regex;
54 pcre_extra *regex_extra;
55 int num_groups;
56} PcreObject;
57
58staticforward PyTypeObject Pcre_Type;
59
60#define PcreObject_Check(v) ((v)->ob_type == &Pcre_Type)
61#define NORMAL 0
62#define CHARCLASS 1
63#define REPLACEMENT 2
64
65#define CHAR 0
66#define MEMORY_REFERENCE 1
67#define SYNTAX 2
68#define NOT_SYNTAX 3
69#define SET 4
70#define WORD_BOUNDARY 5
71#define NOT_WORD_BOUNDARY 6
72#define BEGINNING_OF_BUFFER 7
73#define END_OF_BUFFER 8
74
75
76static PcreObject *
77newPcreObject(arg)
78 PyObject *arg;
79{
80 PcreObject *self;
81 self = PyObject_NEW(PcreObject, &Pcre_Type);
82 if (self == NULL)
83 return NULL;
84 self->regex = NULL;
85 self->regex_extra = NULL;
86 return self;
87}
88
89/* Pcre methods */
90
91static void
92PyPcre_dealloc(self)
93 PcreObject *self;
94{
95 if (self->regex) free(self->regex);
96 if (self->regex_extra) free(self->regex_extra);
97 self->regex=NULL;
98 self->regex_extra=NULL;
99 PyMem_DEL(self);
100}
101
102
103static PyObject *
104PyPcre_exec(self, args)
105 PcreObject *self;
106 PyObject *args;
107{
108 unsigned char *string;
109 int stringlen, pos=0, options=0, i, count;
110 int offsets[100*2]; /* XXX must this be fixed? */
111 PyObject *list;
112
113 if (!PyArg_ParseTuple(args, "s#|ii", &string, &stringlen, &pos, &options))
114 return NULL;
115 count = pcre_exec(self->regex, self->regex_extra,
116 string+pos, stringlen-pos, options,
117 offsets, sizeof(offsets)/sizeof(int) );
118 if (count==PCRE_ERROR_NOMATCH) {Py_INCREF(Py_None); return Py_None;}
119 if (count<0)
120 {
121 PyErr_SetObject(ErrorObject, Py_BuildValue("si", "Regex error", count));
122 return NULL;
123 }
124
125 list=PyList_New(self->num_groups+1);
126 if (list==NULL) return NULL;
127 /* XXX count can be >size_offset! */
128 for(i=0; i<=self->num_groups; i++)
129 {
130 PyObject *v;
131 int start=offsets[i*2], end=offsets[i*2+1];
132 /* If the group wasn't affected by the match, return -1, -1 */
133 if (start<0 || count<=i)
134 {start=end=-1;}
135 else
136 {start += pos; end +=pos;}
137 v=Py_BuildValue("ii", start, end);
138 if (v==NULL) {Py_DECREF(list); return NULL;}
139 PyList_SetItem(list, i, v);
140 }
141 return list;
142}
143
144static PyMethodDef Pcre_methods[] = {
145 {"match", (PyCFunction)PyPcre_exec, 1},
146 {NULL, NULL} /* sentinel */
147};
148
149static PyObject *
150PyPcre_getattr(self, name)
151 PcreObject *self;
152 char *name;
153{
154 return Py_FindMethod(Pcre_methods, (PyObject *)self, name);
155}
156
157
158staticforward PyTypeObject Pcre_Type = {
159 PyObject_HEAD_INIT(&PyType_Type)
160 0, /*ob_size*/
161 "Pcre", /*tp_name*/
162 sizeof(PcreObject), /*tp_basicsize*/
163 0, /*tp_itemsize*/
164 /* methods */
165 (destructor)PyPcre_dealloc, /*tp_dealloc*/
166 0, /*tp_print*/
Guido van Rossumcb4d3031997-10-20 23:21:23 +0000167 (getattrfunc)PyPcre_getattr, /*tp_getattr*/
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000168 0, /*tp_setattr*/
169 0, /*tp_compare*/
170 0, /*tp_repr*/
171 0, /*tp_as_number*/
172 0, /*tp_as_sequence*/
173 0, /*tp_as_mapping*/
174 0, /*tp_hash*/
175};
176/* --------------------------------------------------------------------- */
177
178static PyObject *
179PyPcre_compile(self, args)
180 PyObject *self; /* Not used */
181 PyObject *args;
182{
183 PcreObject *rv;
184 PyObject *dictionary;
185 unsigned char *pattern, *newpattern;
186 char *error;
187 int num_zeros, i, j;
188
189 int patternlen, options, erroroffset;
190 if (!PyArg_ParseTuple(args, "s#iO!", &pattern, &patternlen, &options,
191 &PyDict_Type, &dictionary))
192 return NULL;
193 rv = newPcreObject(args);
194 if ( rv == NULL )
195 return NULL;
196
197 /* PCRE doesn't like having null bytes in its pattern, so we have to replace
198 any zeros in the string with the characters '\0'. */
199 num_zeros=1;
200 for(i=0; i<patternlen; i++) {
201 if (pattern[i]==0) num_zeros++;
202 }
203 newpattern=malloc(patternlen+num_zeros);
204 if (newpattern==NULL) {
205 PyErr_SetString(PyExc_MemoryError, "can't allocate memory for new pattern");
206 return NULL;
207 }
208 for (i=j=0; i<patternlen; i++, j++)
209 {
210 if (pattern[i]!=0) newpattern[j]=pattern[i];
211 else {
212 newpattern[j++]='\\';
213 newpattern[j] ='0';
214 }
215 }
216 newpattern[j]='\0';
217
218 rv->regex = pcre_compile(newpattern, options,
219 &error, &erroroffset, dictionary);
220 free(newpattern);
221 if (rv->regex==NULL)
222 {
223 PyMem_DEL(rv);
224 if (!PyErr_Occurred())
Guido van Rossumc3861071997-10-08 02:07:40 +0000225 {
226 PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, erroroffset));
227 }
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000228 return NULL;
229 }
230 rv->regex_extra=pcre_study(rv->regex, 0, &error);
231 if (rv->regex_extra==NULL && error!=NULL)
232 {
233 PyMem_DEL(rv);
234 PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, 0));
235 return NULL;
236 }
237 rv->num_groups = pcre_info(rv->regex, NULL, NULL);
238 if (rv->num_groups<0)
239 {
240 PyErr_SetObject(ErrorObject, Py_BuildValue("si", "Regex error", rv->num_groups));
241 PyMem_DEL(rv);
242 return NULL;
243 }
244 return (PyObject *)rv;
245}
246
247static PyObject *
Guido van Rossumc3861071997-10-08 02:07:40 +0000248PyPcre_expand_escape(pattern, pattern_len, indexptr, typeptr)
249 unsigned char *pattern;
250 int pattern_len, *indexptr, *typeptr;
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000251{
Guido van Rossumc3861071997-10-08 02:07:40 +0000252 unsigned char c;
253 int index = *indexptr;
254
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000255 if (pattern_len<=index)
256 {
257 PyErr_SetString(ErrorObject, "escape ends too soon");
258 return NULL;
259 }
260 c=pattern[index]; index++;
Guido van Rossumc3861071997-10-08 02:07:40 +0000261 *typeptr=CHAR;
262
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000263 switch (c)
264 {
265 case('t'):
Guido van Rossumc3861071997-10-08 02:07:40 +0000266 *indexptr=index;
267 return Py_BuildValue("c", (char)9);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000268 break;
269 case('n'):
Guido van Rossumc3861071997-10-08 02:07:40 +0000270 *indexptr = index;
271 return Py_BuildValue("c", (char)10);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000272 break;
273 case('v'):
Guido van Rossumc3861071997-10-08 02:07:40 +0000274 *indexptr = index;
275 return Py_BuildValue("c", (char)11);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000276 break;
277 case('r'):
Guido van Rossumc3861071997-10-08 02:07:40 +0000278 *indexptr = index;
279 return Py_BuildValue("c", (char)13);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000280 break;
281 case('f'):
Guido van Rossumc3861071997-10-08 02:07:40 +0000282 *indexptr = index;
283 return Py_BuildValue("c", (char)12);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000284 break;
285 case('a'):
Guido van Rossumc3861071997-10-08 02:07:40 +0000286 *indexptr = index;
287 return Py_BuildValue("c", (char)7);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000288 break;
Guido van Rossumc3861071997-10-08 02:07:40 +0000289 case('b'):
290 *indexptr=index;
291 return Py_BuildValue("c", (char)8);
292 break;
293
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000294 case('x'):
295 {
296 int end, length;
297 unsigned char *string;
Guido van Rossumc3861071997-10-08 02:07:40 +0000298 PyObject *v;
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000299
300 end=index;
301 while (end<pattern_len &&
302 ( pcre_ctypes[ pattern[end] ] & ctype_xdigit ) )
303 end++;
304 if (end==index)
305 {
306 PyErr_SetString(ErrorObject, "\\x must be followed by hex digits");
307 return NULL;
308 }
309 length=end-index;
310 string=malloc(length+4+1);
311 if (string==NULL)
312 {
313 PyErr_SetString(PyExc_MemoryError, "can't allocate memory for \\x string");
314 return NULL;
315 }
316 /* Create a string containing "\x<hexdigits>", which will be
317 passed to eval() */
318 string[0]=string[length+3]='"';
319 string[1]='\\';
320 string[length+4]='\0';
321 memcpy(string+2, pattern+index-1, length+1);
322 v=PyRun_String((char *)string, Py_eval_input,
323 PyEval_GetGlobals(), PyEval_GetLocals());
324 free(string);
325 /* The evaluation raised an exception */
326 if (v==NULL) return NULL;
Guido van Rossumc3861071997-10-08 02:07:40 +0000327 *indexptr = end;
328 return v;
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000329 }
330 break;
331
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000332 case('E'): case('G'): case('L'): case('Q'):
333 case('U'): case('l'): case('u'):
334 {
335 char message[50];
336 sprintf(message, "\\%c is not allowed", c);
337 PyErr_SetString(ErrorObject, message);
338 return NULL;
339 }
340
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000341 case('g'):
342 {
343 int end, valid, i;
344 if (pattern_len<=index)
345 {
346 PyErr_SetString(ErrorObject, "unfinished symbolic reference");
347 return NULL;
348 }
349 if (pattern[index]!='<')
350 {
351 PyErr_SetString(ErrorObject, "missing < in symbolic reference");
352 return NULL;
353 }
354 index++;
355 end=index;
356 while (end<pattern_len && pattern[end]!='>')
357 end++;
358 if (end==pattern_len)
359 {
360 PyErr_SetString(ErrorObject, "unfinished symbolic reference");
361 return NULL;
362 }
363 valid=1;
364 if (index==end /* Zero-length name */
365 || !(pcre_ctypes[pattern[index]] & ctype_word) /* First char. not alphanumeric */
366 || (pcre_ctypes[pattern[index]] & ctype_digit) ) /* First char. a digit */
367 valid=0;
368
369 for(i=index+1; i<end; i++)
370 {
371 if (!(pcre_ctypes[pattern[i]] & ctype_word) )
372 valid=0;
373 }
374 if (!valid)
375 {
376 /* XXX should include the text of the reference */
377 PyErr_SetString(ErrorObject, "illegal symbolic reference");
378 return NULL;
379 }
380
Guido van Rossumc3861071997-10-08 02:07:40 +0000381 *typeptr = MEMORY_REFERENCE;
382 *indexptr = end+1;
383 return Py_BuildValue("s#", pattern+index, end-index);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000384 }
385 break;
386
387 case('0'):
388 {
389 /* \0 always indicates an octal escape, so we consume up to 3
390 characters, as long as they're all octal digits */
391 int octval=0, i;
392 index--;
393 for(i=index;
394 i<=index+2 && i<pattern_len
395 && (pcre_ctypes[ pattern[i] ] & ctype_odigit );
396 i++)
397 {
398 octval = octval * 8 + pattern[i] - '0';
399 }
400 if (octval>255)
401 {
402 PyErr_SetString(ErrorObject, "octal value out of range");
403 return NULL;
404 }
Guido van Rossumc3861071997-10-08 02:07:40 +0000405 *indexptr = i;
406 return Py_BuildValue("c", (unsigned char)octval);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000407 }
408 break;
409 case('1'): case('2'): case('3'): case('4'):
410 case('5'): case('6'): case('7'): case('8'):
411 case('9'):
412 {
413 /* Handle \?, where ? is from 1 through 9 */
414 int value=0;
415 index--;
416 /* If it's at least a two-digit reference, like \34, it might
417 either be a 3-digit octal escape (\123) or a 2-digit
418 decimal memory reference (\34) */
419
420 if ( (index+1) <pattern_len &&
421 (pcre_ctypes[ pattern[index+1] ] & ctype_digit) )
422 {
423 if ( (index+2) <pattern_len &&
424 (pcre_ctypes[ pattern[index+2] ] & ctype_odigit) &&
425 (pcre_ctypes[ pattern[index+1] ] & ctype_odigit) &&
426 (pcre_ctypes[ pattern[index ] ] & ctype_odigit)
427 )
428 {
429 /* 3 octal digits */
430 value= 8*8*(pattern[index ]-'0') +
431 8*(pattern[index+1]-'0') +
432 (pattern[index+2]-'0');
433 if (value>255)
434 {
435 PyErr_SetString(ErrorObject, "octal value out of range");
436 return NULL;
437 }
Guido van Rossumc3861071997-10-08 02:07:40 +0000438 *indexptr = index+3;
439 return Py_BuildValue("c", (unsigned char)value);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000440 }
441 else
442 {
443 /* 2-digit form, so it's a memory reference */
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000444 value= 10*(pattern[index ]-'0') +
445 (pattern[index+1]-'0');
446 if (value<1 || EXTRACT_MAX<=value)
447 {
448 PyErr_SetString(ErrorObject, "memory reference out of range");
449 return NULL;
450 }
Guido van Rossumc3861071997-10-08 02:07:40 +0000451 *typeptr = MEMORY_REFERENCE;
452 *indexptr = index+2;
453 return Py_BuildValue("i", value);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000454 }
455 }
456 else
457 {
458 /* Single-digit form, like \2, so it's a memory reference */
Guido van Rossumc3861071997-10-08 02:07:40 +0000459 *typeptr = MEMORY_REFERENCE;
460 *indexptr = index+1;
461 return Py_BuildValue("i", pattern[index]-'0');
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000462 }
463 }
464 break;
465
466 default:
Guido van Rossumc3861071997-10-08 02:07:40 +0000467 *indexptr = index;
468 return Py_BuildValue("c", c);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000469 break;
470 }
471}
472
473static PyObject *
474PyPcre_expand(self, args)
475 PyObject *self;
476 PyObject *args;
477{
478 PyObject *results, *match_obj;
479 PyObject *repl_obj, *newstring;
480 unsigned char *repl;
481 int size, total_len, i, start, pos;
482
483 if (!PyArg_ParseTuple(args, "OS", &match_obj, &repl_obj))
484 return NULL;
485
486 repl=(unsigned char *)PyString_AsString(repl_obj);
487 size=PyString_Size(repl_obj);
488 results=PyList_New(0);
489 if (results==NULL) return NULL;
490 for(start=total_len=i=0; i<size; i++)
491 {
492 if (repl[i]=='\\')
493 {
Guido van Rossumc3861071997-10-08 02:07:40 +0000494 PyObject *value;
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000495 int escape_type;
496
497 if (start!=i)
498 {
499 PyList_Append(results,
500 PyString_FromStringAndSize((char *)repl+start, i-start));
501 total_len += i-start;
502 }
503 i++;
Guido van Rossumc3861071997-10-08 02:07:40 +0000504 value=PyPcre_expand_escape(repl, size, &i, &escape_type);
505 if (value==NULL)
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000506 {
507 /* PyPcre_expand_escape triggered an exception of some sort,
508 so just return */
509 Py_DECREF(results);
510 return NULL;
511 }
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000512 switch (escape_type)
513 {
514 case (CHAR):
515 PyList_Append(results, value);
516 total_len += PyString_Size(value);
517 break;
518 case(MEMORY_REFERENCE):
519 {
520 PyObject *r, *tuple, *result;
521 r=PyObject_GetAttrString(match_obj, "group");
522 tuple=PyTuple_New(1);
523 Py_INCREF(value);
524 PyTuple_SetItem(tuple, 0, value);
525 result=PyEval_CallObject(r, tuple);
526 Py_DECREF(r); Py_DECREF(tuple);
527 if (result==NULL)
528 {
529 /* The group() method trigged an exception of some sort */
530 Py_DECREF(results);
531 return NULL;
532 }
533 if (result==Py_None)
534 {
535 char message[50];
536 sprintf(message,
537 "group %li did not contribute to the match",
538 PyInt_AsLong(value));
539 PyErr_SetString(ErrorObject,
540 message);
541 Py_DECREF(result);
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000542 Py_DECREF(results);
543 return NULL;
544 }
545 /* XXX typecheck that it's a string! */
546 PyList_Append(results, result);
547 total_len += PyString_Size(result);
548 Py_DECREF(result);
549 }
550 break;
551 default:
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000552 Py_DECREF(results);
553 PyErr_SetString(ErrorObject,
554 "bad escape in replacement");
555 return NULL;
556 }
Guido van Rossumc3861071997-10-08 02:07:40 +0000557 start=i;
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000558 i--; /* Decrement now, because the 'for' loop will increment it */
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000559 }
560 } /* endif repl[i]!='\\' */
561
562 if (start!=i)
563 {
564 PyList_Append(results, PyString_FromStringAndSize((char *)repl+start, i-start));
565 total_len += i-start;
566 }
567
568 /* Whew! Now we've constructed a list containing various pieces of
569 strings that will make up our final result. So, iterate over
570 the list concatenating them. A new string measuring total_len
571 bytes is allocated and filled in. */
572
573 newstring=PyString_FromStringAndSize(NULL, total_len);
574 if (newstring==NULL)
575 {
576 Py_DECREF(results);
577 return NULL;
578 }
579
580 repl=(unsigned char *)PyString_AsString(newstring);
581 for (pos=i=0; i<PyList_Size(results); i++)
582 {
583 PyObject *item=PyList_GetItem(results, i);
584 memcpy(repl+pos, PyString_AsString(item), PyString_Size(item) );
585 pos += PyString_Size(item);
586 }
587 Py_DECREF(results);
588 return newstring;
589}
590
591
592/* List of functions defined in the module */
593
594static PyMethodDef pcre_methods[] = {
595 {"pcre_compile", PyPcre_compile, 1},
596 {"pcre_expand", PyPcre_expand, 1},
597 {NULL, NULL} /* sentinel */
598};
599
600
601/*
602 * Convenience routine to export an integer value.
603 * For simplicity, errors (which are unlikely anyway) are ignored.
604 */
605
606static void
607insint(d, name, value)
608 PyObject * d;
609 char * name;
610 int value;
611{
612 PyObject *v = PyInt_FromLong((long) value);
613 if (v == NULL) {
614 /* Don't bother reporting this error */
615 PyErr_Clear();
616 }
617 else {
618 PyDict_SetItemString(d, name, v);
619 Py_DECREF(v);
620 }
621}
622
623
624/* Initialization function for the module (*must* be called initpcre) */
625
626void
627initpcre()
628{
629 PyObject *m, *d;
Guido van Rossum51b3aa31997-10-06 14:43:11 +0000630
631 /* Create the module and add the functions */
632 m = Py_InitModule("pcre", pcre_methods);
633
634 /* Add some symbolic constants to the module */
635 d = PyModule_GetDict(m);
636 ErrorObject = PyString_FromString("pcre.error");
637 PyDict_SetItemString(d, "error", ErrorObject);
638
639 /* Insert the flags */
640 insint(d, "IGNORECASE", PCRE_CASELESS);
641 insint(d, "ANCHORED", PCRE_ANCHORED);
642 insint(d, "MULTILINE", PCRE_MULTILINE);
643 insint(d, "DOTALL", PCRE_DOTALL);
644 insint(d, "VERBOSE", PCRE_EXTENDED);
645
646 /* Insert the opcodes */
647 insint(d, "OP_END", OP_END);
648 insint(d, "OP_SOD", OP_SOD);
649 insint(d, "OP_NOT_WORD_BOUNDARY", OP_NOT_WORD_BOUNDARY);
650 insint(d, "OP_WORD_BOUNDARY", OP_WORD_BOUNDARY);
651 insint(d, "OP_NOT_DIGIT", OP_NOT_DIGIT);
652 insint(d, "OP_NOT_WHITESPACE", OP_NOT_WHITESPACE);
653 insint(d, "OP_WHITESPACE", OP_WHITESPACE);
654 insint(d, "OP_NOT_WORDCHAR", OP_NOT_WORDCHAR);
655 insint(d, "OP_WORDCHAR", OP_WORDCHAR);
656 insint(d, "OP_EOD", OP_EOD);
657 insint(d, "OP_CIRC", OP_CIRC);
658 insint(d, "OP_DOLL", OP_DOLL);
659 insint(d, "OP_ANY", OP_ANY);
660 insint(d, "OP_CHARS", OP_CHARS);
661
662 insint(d, "OP_STAR", OP_STAR);
663 insint(d, "OP_MINSTAR", OP_MINSTAR);
664 insint(d, "OP_PLUS", OP_PLUS);
665 insint(d, "OP_MINPLUS", OP_MINPLUS);
666 insint(d, "OP_QUERY", OP_QUERY);
667 insint(d, "OP_MINQUERY", OP_MINQUERY);
668 insint(d, "OP_UPTO", OP_UPTO);
669 insint(d, "OP_MINUPTO", OP_MINUPTO);
670 insint(d, "OP_EXACT", OP_EXACT);
671
672 insint(d, "OP_TYPESTAR", OP_TYPESTAR);
673 insint(d, "OP_TYPEMINSTAR", OP_TYPEMINSTAR);
674 insint(d, "OP_TYPEPLUS", OP_TYPEPLUS);
675 insint(d, "OP_TYPEMINPLUS", OP_TYPEMINPLUS);
676 insint(d, "OP_TYPEQUERY", OP_TYPEQUERY);
677 insint(d, "OP_TYPEMINQUERY", OP_TYPEMINQUERY);
678 insint(d, "OP_TYPEUPTO", OP_TYPEUPTO);
679 insint(d, "OP_TYPEMINUPTO", OP_TYPEMINUPTO);
680 insint(d, "OP_TYPEEXACT", OP_TYPEEXACT);
681
682 insint(d, "OP_CRSTAR", OP_CRSTAR);
683 insint(d, "OP_CRMINSTAR", OP_CRMINSTAR);
684 insint(d, "OP_CRPLUS", OP_CRPLUS);
685 insint(d, "OP_CRMINPLUS", OP_CRMINPLUS);
686 insint(d, "OP_CRQUERY", OP_CRQUERY);
687 insint(d, "OP_CRMINQUERY", OP_CRMINQUERY);
688 insint(d, "OP_CRRANGE", OP_CRRANGE);
689 insint(d, "OP_CRMINRANGE", OP_CRMINRANGE);
690
691 insint(d, "OP_CLASS", OP_CLASS);
692 insint(d, "OP_NEGCLASS", OP_NEGCLASS);
693 insint(d, "OP_REF", OP_REF);
694
695 insint(d, "OP_ALT", OP_ALT);
696 insint(d, "OP_KET", OP_KET);
697 insint(d, "OP_KETRMAX", OP_KETRMAX);
698 insint(d, "OP_KETRMIN", OP_KETRMIN);
699
700 insint(d, "OP_ASSERT", OP_ASSERT);
701 insint(d, "OP_ASSERT_NOT", OP_ASSERT_NOT);
702
703 insint(d, "OP_BRAZERO", OP_BRAZERO);
704 insint(d, "OP_BRAMINZERO", OP_BRAMINZERO);
705 insint(d, "OP_BRA", OP_BRA);
706
707 /* Check for errors */
708 if (PyErr_Occurred())
709 Py_FatalError("can't initialize module pcre");
710}
711