Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Secret Labs' Regular Expression Engine |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 3 | * |
Fredrik Lundh | 8094611 | 2000-06-29 18:03:25 +0000 | [diff] [blame] | 4 | * regular expression matching engine |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved. |
| 7 | * |
| 8 | * See the _sre.c file for information on usage and redistribution. |
| 9 | */ |
| 10 | |
| 11 | #ifndef SRE_INCLUDED |
| 12 | #define SRE_INCLUDED |
| 13 | |
| 14 | #include "sre_constants.h" |
| 15 | |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 16 | /* size of a code word (must be unsigned short or larger) */ |
| 17 | #define SRE_CODE unsigned short |
| 18 | |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 19 | typedef struct { |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 20 | PyObject_VAR_HEAD |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 21 | int groups; |
| 22 | PyObject* groupindex; |
Fredrik Lundh | c230173 | 2000-07-02 22:25:39 +0000 | [diff] [blame] | 23 | PyObject* indexgroup; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 24 | /* compatibility */ |
| 25 | PyObject* pattern; /* pattern source (or None) */ |
| 26 | int flags; /* flags used when compiling pattern source */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 27 | /* pattern code */ |
| 28 | SRE_CODE code[1]; |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 29 | } PatternObject; |
| 30 | |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 31 | #define PatternObject_GetCode(o) (((PatternObject*)(o))->code) |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 32 | |
| 33 | typedef struct { |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 34 | PyObject_VAR_HEAD |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 35 | PyObject* string; /* link to the target string */ |
| 36 | PatternObject* pattern; /* link to the regex (pattern) object */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 37 | int pos, endpos; /* current target slice */ |
| 38 | int lastindex; /* last index marker seen by the engine (-1 if none) */ |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 39 | int groups; /* number of groups (start/end marks) */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 40 | int mark[1]; |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 41 | } MatchObject; |
| 42 | |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 43 | typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch); |
| 44 | |
| 45 | typedef struct { |
| 46 | /* stack elements */ |
| 47 | SRE_CODE* pattern; |
| 48 | void* ptr; |
Fredrik Lundh | 72b82ba | 2000-07-03 21:31:48 +0000 | [diff] [blame] | 49 | int mark; |
| 50 | void* mark0; |
| 51 | void* mark1; |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 52 | } SRE_STACK; |
| 53 | |
Fredrik Lundh | be2211e | 2000-06-29 16:57:40 +0000 | [diff] [blame] | 54 | /* FIXME: <fl> shouldn't be a constant, really... */ |
| 55 | #define SRE_MARK_SIZE 200 |
| 56 | |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 57 | typedef struct { |
| 58 | /* string pointers */ |
| 59 | void* ptr; /* current position (also end of current slice) */ |
| 60 | void* beginning; /* start of original string */ |
| 61 | void* start; /* start of current slice */ |
| 62 | void* end; /* end of original string */ |
| 63 | /* character size */ |
| 64 | int charsize; |
| 65 | /* registers */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 66 | int lastindex; |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 67 | int lastmark; |
Fredrik Lundh | be2211e | 2000-06-29 16:57:40 +0000 | [diff] [blame] | 68 | void* mark[SRE_MARK_SIZE]; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 69 | /* backtracking stack */ |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 70 | SRE_STACK* stack; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 71 | int stacksize; |
| 72 | int stackbase; |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 73 | /* hooks */ |
Fredrik Lundh | b389df3 | 2000-06-29 12:48:37 +0000 | [diff] [blame] | 74 | SRE_TOLOWER_HOOK lower; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 75 | } SRE_STATE; |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 76 | |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 77 | typedef struct { |
Fredrik Lundh | be2211e | 2000-06-29 16:57:40 +0000 | [diff] [blame] | 78 | /* scanner (internal helper object) */ |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 79 | PyObject_HEAD |
| 80 | PyObject* pattern; |
| 81 | PyObject* string; |
| 82 | SRE_STATE state; |
Fredrik Lundh | be2211e | 2000-06-29 16:57:40 +0000 | [diff] [blame] | 83 | } ScannerObject; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 84 | |
| 85 | #endif |