blob: 7c4136abb8c37f645914830f0605aafad337db5a [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*/
167 PyPcre_getattr, /*tp_getattr*/
168 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())
225 PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, erroroffset));
226 return NULL;
227 }
228 rv->regex_extra=pcre_study(rv->regex, 0, &error);
229 if (rv->regex_extra==NULL && error!=NULL)
230 {
231 PyMem_DEL(rv);
232 PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, 0));
233 return NULL;
234 }
235 rv->num_groups = pcre_info(rv->regex, NULL, NULL);
236 if (rv->num_groups<0)
237 {
238 PyErr_SetObject(ErrorObject, Py_BuildValue("si", "Regex error", rv->num_groups));
239 PyMem_DEL(rv);
240 return NULL;
241 }
242 return (PyObject *)rv;
243}
244
245static PyObject *
246PyPcre_expand_escape(self, args)
247 PyObject *self;
248 PyObject *args;
249{
250 unsigned char c, *pattern;
251 int index, pattern_len;
252 const int context=REPLACEMENT;
253
254 if (!PyArg_ParseTuple(args, "s#i", &pattern, &pattern_len, &index))
255 return NULL;
256 if (pattern_len<=index)
257 {
258 PyErr_SetString(ErrorObject, "escape ends too soon");
259 return NULL;
260 }
261 c=pattern[index]; index++;
262 switch (c)
263 {
264 case('t'):
265 return Py_BuildValue("ici", CHAR, (char)9, index);
266 break;
267 case('n'):
268 return Py_BuildValue("ici", CHAR, (char)10, index);
269 break;
270 case('v'):
271 return Py_BuildValue("ici", CHAR, (char)11, index);
272 break;
273 case('r'):
274 return Py_BuildValue("ici", CHAR, (char)13, index);
275 break;
276 case('f'):
277 return Py_BuildValue("ici", CHAR, (char)12, index);
278 break;
279 case('a'):
280 return Py_BuildValue("ici", CHAR, (char)7, index);
281 break;
282 case('x'):
283 {
284 int end, length;
285 unsigned char *string;
286 PyObject *v, *result;
287
288 end=index;
289 while (end<pattern_len &&
290 ( pcre_ctypes[ pattern[end] ] & ctype_xdigit ) )
291 end++;
292 if (end==index)
293 {
294 PyErr_SetString(ErrorObject, "\\x must be followed by hex digits");
295 return NULL;
296 }
297 length=end-index;
298 string=malloc(length+4+1);
299 if (string==NULL)
300 {
301 PyErr_SetString(PyExc_MemoryError, "can't allocate memory for \\x string");
302 return NULL;
303 }
304 /* Create a string containing "\x<hexdigits>", which will be
305 passed to eval() */
306 string[0]=string[length+3]='"';
307 string[1]='\\';
308 string[length+4]='\0';
309 memcpy(string+2, pattern+index-1, length+1);
310 v=PyRun_String((char *)string, Py_eval_input,
311 PyEval_GetGlobals(), PyEval_GetLocals());
312 free(string);
313 /* The evaluation raised an exception */
314 if (v==NULL) return NULL;
315 result=Py_BuildValue("iOi", CHAR, v, end);
316 Py_DECREF(v);
317 return result;
318 }
319 break;
320
321 case('b'):
322 if (context!=NORMAL)
323 return Py_BuildValue("ici", CHAR, (char)8, index);
324 else
325 {
326 unsigned char empty_string[1];
327 empty_string[0]='\0';
328 return Py_BuildValue("isi", WORD_BOUNDARY, empty_string, index);
329 }
330 break;
331 case('B'):
332 if (context!=NORMAL)
333 return Py_BuildValue("ici", CHAR, 'B', index);
334 else
335 {
336 unsigned char empty_string[1];
337 empty_string[0]='\0';
338 return Py_BuildValue("isi", NOT_WORD_BOUNDARY, empty_string, index);
339 }
340 break;
341 case('A'):
342 if (context!=NORMAL)
343 return Py_BuildValue("ici", CHAR, 'A', index);
344 else
345 {
346 unsigned char empty_string[1];
347 empty_string[0]='\0';
348 return Py_BuildValue("isi", BEGINNING_OF_BUFFER, empty_string, index);
349 }
350 break;
351 case('Z'):
352 if (context!=NORMAL)
353 return Py_BuildValue("ici", CHAR, 'Z', index);
354 else
355 {
356 unsigned char empty_string[1];
357 empty_string[0]='\0';
358 return Py_BuildValue("isi", END_OF_BUFFER, empty_string, index);
359 }
360 break;
361 case('E'): case('G'): case('L'): case('Q'):
362 case('U'): case('l'): case('u'):
363 {
364 char message[50];
365 sprintf(message, "\\%c is not allowed", c);
366 PyErr_SetString(ErrorObject, message);
367 return NULL;
368 }
369
370 case ('w'):
371 return Py_BuildValue("ici", CHAR, 'w', index);
372 break;
373 case ('W'):
374 return Py_BuildValue("ici", CHAR, 'W', index);
375 break;
376 case ('s'):
377 return Py_BuildValue("ici", CHAR, 's', index);
378 break;
379 case ('S'):
380 return Py_BuildValue("ici", CHAR, 'S', index);
381 break;
382
383 case ('d'):
384 return Py_BuildValue("ici", CHAR, 'd', index);
385 break;
386 case ('D'):
387 return Py_BuildValue("ici", CHAR, 'D', index);
388 break;
389
390 case('g'):
391 {
392 int end, valid, i;
393 if (pattern_len<=index)
394 {
395 PyErr_SetString(ErrorObject, "unfinished symbolic reference");
396 return NULL;
397 }
398 if (pattern[index]!='<')
399 {
400 PyErr_SetString(ErrorObject, "missing < in symbolic reference");
401 return NULL;
402 }
403 index++;
404 end=index;
405 while (end<pattern_len && pattern[end]!='>')
406 end++;
407 if (end==pattern_len)
408 {
409 PyErr_SetString(ErrorObject, "unfinished symbolic reference");
410 return NULL;
411 }
412 valid=1;
413 if (index==end /* Zero-length name */
414 || !(pcre_ctypes[pattern[index]] & ctype_word) /* First char. not alphanumeric */
415 || (pcre_ctypes[pattern[index]] & ctype_digit) ) /* First char. a digit */
416 valid=0;
417
418 for(i=index+1; i<end; i++)
419 {
420 if (!(pcre_ctypes[pattern[i]] & ctype_word) )
421 valid=0;
422 }
423 if (!valid)
424 {
425 /* XXX should include the text of the reference */
426 PyErr_SetString(ErrorObject, "illegal symbolic reference");
427 return NULL;
428 }
429
430 return Py_BuildValue("is#i", MEMORY_REFERENCE,
431 pattern+index, end-index,
432 end+1);
433 }
434 break;
435
436 case('0'):
437 {
438 /* \0 always indicates an octal escape, so we consume up to 3
439 characters, as long as they're all octal digits */
440 int octval=0, i;
441 index--;
442 for(i=index;
443 i<=index+2 && i<pattern_len
444 && (pcre_ctypes[ pattern[i] ] & ctype_odigit );
445 i++)
446 {
447 octval = octval * 8 + pattern[i] - '0';
448 }
449 if (octval>255)
450 {
451 PyErr_SetString(ErrorObject, "octal value out of range");
452 return NULL;
453 }
454 return Py_BuildValue("ici", CHAR, (unsigned char)octval, i);
455 }
456 break;
457 case('1'): case('2'): case('3'): case('4'):
458 case('5'): case('6'): case('7'): case('8'):
459 case('9'):
460 {
461 /* Handle \?, where ? is from 1 through 9 */
462 int value=0;
463 index--;
464 /* If it's at least a two-digit reference, like \34, it might
465 either be a 3-digit octal escape (\123) or a 2-digit
466 decimal memory reference (\34) */
467
468 if ( (index+1) <pattern_len &&
469 (pcre_ctypes[ pattern[index+1] ] & ctype_digit) )
470 {
471 if ( (index+2) <pattern_len &&
472 (pcre_ctypes[ pattern[index+2] ] & ctype_odigit) &&
473 (pcre_ctypes[ pattern[index+1] ] & ctype_odigit) &&
474 (pcre_ctypes[ pattern[index ] ] & ctype_odigit)
475 )
476 {
477 /* 3 octal digits */
478 value= 8*8*(pattern[index ]-'0') +
479 8*(pattern[index+1]-'0') +
480 (pattern[index+2]-'0');
481 if (value>255)
482 {
483 PyErr_SetString(ErrorObject, "octal value out of range");
484 return NULL;
485 }
486 return Py_BuildValue("ici", CHAR, (unsigned char)value, index+3);
487 }
488 else
489 {
490 /* 2-digit form, so it's a memory reference */
491 if (context==CHARCLASS)
492 {
493 PyErr_SetString(ErrorObject, "cannot reference a register "
494 "from inside a character class");
495 return NULL;
496 }
497 value= 10*(pattern[index ]-'0') +
498 (pattern[index+1]-'0');
499 if (value<1 || EXTRACT_MAX<=value)
500 {
501 PyErr_SetString(ErrorObject, "memory reference out of range");
502 return NULL;
503 }
504 return Py_BuildValue("iii", MEMORY_REFERENCE,
505 value, index+2);
506 }
507 }
508 else
509 {
510 /* Single-digit form, like \2, so it's a memory reference */
511 if (context==CHARCLASS)
512 {
513 PyErr_SetString(ErrorObject, "cannot reference a register "
514 "from inside a character class");
515 return NULL;
516 }
517 return Py_BuildValue("iii", MEMORY_REFERENCE,
518 pattern[index]-'0', index+1);
519 }
520 }
521 break;
522
523 default:
524 return Py_BuildValue("ici", CHAR, c, index);
525 break;
526 }
527}
528
529static PyObject *
530PyPcre_expand(self, args)
531 PyObject *self;
532 PyObject *args;
533{
534 PyObject *results, *match_obj;
535 PyObject *repl_obj, *newstring;
536 unsigned char *repl;
537 int size, total_len, i, start, pos;
538
539 if (!PyArg_ParseTuple(args, "OS", &match_obj, &repl_obj))
540 return NULL;
541
542 repl=(unsigned char *)PyString_AsString(repl_obj);
543 size=PyString_Size(repl_obj);
544 results=PyList_New(0);
545 if (results==NULL) return NULL;
546 for(start=total_len=i=0; i<size; i++)
547 {
548 if (repl[i]=='\\')
549 {
550 PyObject *args, *t, *value;
551 int escape_type;
552
553 if (start!=i)
554 {
555 PyList_Append(results,
556 PyString_FromStringAndSize((char *)repl+start, i-start));
557 total_len += i-start;
558 }
559 i++;
560 args=Py_BuildValue("Oi", repl_obj, i);
561 t=PyPcre_expand_escape(NULL, args);
562 Py_DECREF(args);
563 if (t==NULL)
564 {
565 /* PyPcre_expand_escape triggered an exception of some sort,
566 so just return */
567 Py_DECREF(results);
568 return NULL;
569 }
570 value=PyTuple_GetItem(t, 1);
571 escape_type=PyInt_AsLong(PyTuple_GetItem(t, 0));
572 switch (escape_type)
573 {
574 case (CHAR):
575 PyList_Append(results, value);
576 total_len += PyString_Size(value);
577 break;
578 case(MEMORY_REFERENCE):
579 {
580 PyObject *r, *tuple, *result;
581 r=PyObject_GetAttrString(match_obj, "group");
582 tuple=PyTuple_New(1);
583 Py_INCREF(value);
584 PyTuple_SetItem(tuple, 0, value);
585 result=PyEval_CallObject(r, tuple);
586 Py_DECREF(r); Py_DECREF(tuple);
587 if (result==NULL)
588 {
589 /* The group() method trigged an exception of some sort */
590 Py_DECREF(results);
591 return NULL;
592 }
593 if (result==Py_None)
594 {
595 char message[50];
596 sprintf(message,
597 "group %li did not contribute to the match",
598 PyInt_AsLong(value));
599 PyErr_SetString(ErrorObject,
600 message);
601 Py_DECREF(result);
602 Py_DECREF(t);
603 Py_DECREF(results);
604 return NULL;
605 }
606 /* XXX typecheck that it's a string! */
607 PyList_Append(results, result);
608 total_len += PyString_Size(result);
609 Py_DECREF(result);
610 }
611 break;
612 default:
613 Py_DECREF(t);
614 Py_DECREF(results);
615 PyErr_SetString(ErrorObject,
616 "bad escape in replacement");
617 return NULL;
618 }
619 i=start=PyInt_AsLong(PyTuple_GetItem(t, 2));
620 i--; /* Decrement now, because the 'for' loop will increment it */
621 Py_DECREF(t);
622 }
623 } /* endif repl[i]!='\\' */
624
625 if (start!=i)
626 {
627 PyList_Append(results, PyString_FromStringAndSize((char *)repl+start, i-start));
628 total_len += i-start;
629 }
630
631 /* Whew! Now we've constructed a list containing various pieces of
632 strings that will make up our final result. So, iterate over
633 the list concatenating them. A new string measuring total_len
634 bytes is allocated and filled in. */
635
636 newstring=PyString_FromStringAndSize(NULL, total_len);
637 if (newstring==NULL)
638 {
639 Py_DECREF(results);
640 return NULL;
641 }
642
643 repl=(unsigned char *)PyString_AsString(newstring);
644 for (pos=i=0; i<PyList_Size(results); i++)
645 {
646 PyObject *item=PyList_GetItem(results, i);
647 memcpy(repl+pos, PyString_AsString(item), PyString_Size(item) );
648 pos += PyString_Size(item);
649 }
650 Py_DECREF(results);
651 return newstring;
652}
653
654
655/* List of functions defined in the module */
656
657static PyMethodDef pcre_methods[] = {
658 {"pcre_compile", PyPcre_compile, 1},
659 {"pcre_expand", PyPcre_expand, 1},
660 {NULL, NULL} /* sentinel */
661};
662
663
664/*
665 * Convenience routine to export an integer value.
666 * For simplicity, errors (which are unlikely anyway) are ignored.
667 */
668
669static void
670insint(d, name, value)
671 PyObject * d;
672 char * name;
673 int value;
674{
675 PyObject *v = PyInt_FromLong((long) value);
676 if (v == NULL) {
677 /* Don't bother reporting this error */
678 PyErr_Clear();
679 }
680 else {
681 PyDict_SetItemString(d, name, v);
682 Py_DECREF(v);
683 }
684}
685
686
687/* Initialization function for the module (*must* be called initpcre) */
688
689void
690initpcre()
691{
692 PyObject *m, *d;
693 int a;
694
695 /* Create the module and add the functions */
696 m = Py_InitModule("pcre", pcre_methods);
697
698 /* Add some symbolic constants to the module */
699 d = PyModule_GetDict(m);
700 ErrorObject = PyString_FromString("pcre.error");
701 PyDict_SetItemString(d, "error", ErrorObject);
702
703 /* Insert the flags */
704 insint(d, "IGNORECASE", PCRE_CASELESS);
705 insint(d, "ANCHORED", PCRE_ANCHORED);
706 insint(d, "MULTILINE", PCRE_MULTILINE);
707 insint(d, "DOTALL", PCRE_DOTALL);
708 insint(d, "VERBOSE", PCRE_EXTENDED);
709
710 /* Insert the opcodes */
711 insint(d, "OP_END", OP_END);
712 insint(d, "OP_SOD", OP_SOD);
713 insint(d, "OP_NOT_WORD_BOUNDARY", OP_NOT_WORD_BOUNDARY);
714 insint(d, "OP_WORD_BOUNDARY", OP_WORD_BOUNDARY);
715 insint(d, "OP_NOT_DIGIT", OP_NOT_DIGIT);
716 insint(d, "OP_NOT_WHITESPACE", OP_NOT_WHITESPACE);
717 insint(d, "OP_WHITESPACE", OP_WHITESPACE);
718 insint(d, "OP_NOT_WORDCHAR", OP_NOT_WORDCHAR);
719 insint(d, "OP_WORDCHAR", OP_WORDCHAR);
720 insint(d, "OP_EOD", OP_EOD);
721 insint(d, "OP_CIRC", OP_CIRC);
722 insint(d, "OP_DOLL", OP_DOLL);
723 insint(d, "OP_ANY", OP_ANY);
724 insint(d, "OP_CHARS", OP_CHARS);
725
726 insint(d, "OP_STAR", OP_STAR);
727 insint(d, "OP_MINSTAR", OP_MINSTAR);
728 insint(d, "OP_PLUS", OP_PLUS);
729 insint(d, "OP_MINPLUS", OP_MINPLUS);
730 insint(d, "OP_QUERY", OP_QUERY);
731 insint(d, "OP_MINQUERY", OP_MINQUERY);
732 insint(d, "OP_UPTO", OP_UPTO);
733 insint(d, "OP_MINUPTO", OP_MINUPTO);
734 insint(d, "OP_EXACT", OP_EXACT);
735
736 insint(d, "OP_TYPESTAR", OP_TYPESTAR);
737 insint(d, "OP_TYPEMINSTAR", OP_TYPEMINSTAR);
738 insint(d, "OP_TYPEPLUS", OP_TYPEPLUS);
739 insint(d, "OP_TYPEMINPLUS", OP_TYPEMINPLUS);
740 insint(d, "OP_TYPEQUERY", OP_TYPEQUERY);
741 insint(d, "OP_TYPEMINQUERY", OP_TYPEMINQUERY);
742 insint(d, "OP_TYPEUPTO", OP_TYPEUPTO);
743 insint(d, "OP_TYPEMINUPTO", OP_TYPEMINUPTO);
744 insint(d, "OP_TYPEEXACT", OP_TYPEEXACT);
745
746 insint(d, "OP_CRSTAR", OP_CRSTAR);
747 insint(d, "OP_CRMINSTAR", OP_CRMINSTAR);
748 insint(d, "OP_CRPLUS", OP_CRPLUS);
749 insint(d, "OP_CRMINPLUS", OP_CRMINPLUS);
750 insint(d, "OP_CRQUERY", OP_CRQUERY);
751 insint(d, "OP_CRMINQUERY", OP_CRMINQUERY);
752 insint(d, "OP_CRRANGE", OP_CRRANGE);
753 insint(d, "OP_CRMINRANGE", OP_CRMINRANGE);
754
755 insint(d, "OP_CLASS", OP_CLASS);
756 insint(d, "OP_NEGCLASS", OP_NEGCLASS);
757 insint(d, "OP_REF", OP_REF);
758
759 insint(d, "OP_ALT", OP_ALT);
760 insint(d, "OP_KET", OP_KET);
761 insint(d, "OP_KETRMAX", OP_KETRMAX);
762 insint(d, "OP_KETRMIN", OP_KETRMIN);
763
764 insint(d, "OP_ASSERT", OP_ASSERT);
765 insint(d, "OP_ASSERT_NOT", OP_ASSERT_NOT);
766
767 insint(d, "OP_BRAZERO", OP_BRAZERO);
768 insint(d, "OP_BRAMINZERO", OP_BRAMINZERO);
769 insint(d, "OP_BRA", OP_BRA);
770
771 /* Check for errors */
772 if (PyErr_Occurred())
773 Py_FatalError("can't initialize module pcre");
774}
775