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 */ |
Fredrik Lundh | 8a3ebf8 | 2000-07-23 21:46:17 +0000 | [diff] [blame] | 36 | PyObject* regs; /* cached list of matching spans */ |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 37 | PatternObject* pattern; /* link to the regex (pattern) object */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 38 | int pos, endpos; /* current target slice */ |
| 39 | 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] | 40 | int groups; /* number of groups (start/end marks) */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 41 | int mark[1]; |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 42 | } MatchObject; |
| 43 | |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 44 | typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch); |
| 45 | |
Fredrik Lundh | be2211e | 2000-06-29 16:57:40 +0000 | [diff] [blame] | 46 | /* FIXME: <fl> shouldn't be a constant, really... */ |
| 47 | #define SRE_MARK_SIZE 200 |
| 48 | |
Fredrik Lundh | 29c4ba9 | 2000-08-01 18:20:07 +0000 | [diff] [blame] | 49 | typedef struct SRE_REPEAT_T { |
| 50 | int count; |
| 51 | SRE_CODE* pattern; /* points to REPEAT operator arguments */ |
| 52 | struct SRE_REPEAT_T *prev; /* points to previous repeat context */ |
| 53 | } SRE_REPEAT; |
| 54 | |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 55 | typedef struct { |
| 56 | /* string pointers */ |
| 57 | void* ptr; /* current position (also end of current slice) */ |
| 58 | void* beginning; /* start of original string */ |
| 59 | void* start; /* start of current slice */ |
| 60 | void* end; /* end of original string */ |
Fredrik Lundh | 8a3ebf8 | 2000-07-23 21:46:17 +0000 | [diff] [blame] | 61 | /* attributes for the match object */ |
| 62 | PyObject* string; |
| 63 | int pos, endpos; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 64 | /* character size */ |
| 65 | int charsize; |
| 66 | /* registers */ |
Fredrik Lundh | 6f01398 | 2000-07-03 18:44:21 +0000 | [diff] [blame] | 67 | int lastindex; |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 68 | int lastmark; |
Fredrik Lundh | be2211e | 2000-06-29 16:57:40 +0000 | [diff] [blame] | 69 | void* mark[SRE_MARK_SIZE]; |
Fredrik Lundh | 29c4ba9 | 2000-08-01 18:20:07 +0000 | [diff] [blame] | 70 | /* dynamically allocated stuff */ |
| 71 | void** mark_stack; |
| 72 | int mark_stack_size; |
| 73 | int mark_stack_base; |
| 74 | SRE_REPEAT *repeat; /* current repeat context */ |
Fredrik Lundh | 102f3ad | 2000-06-29 08:55:54 +0000 | [diff] [blame] | 75 | /* hooks */ |
Fredrik Lundh | b389df3 | 2000-06-29 12:48:37 +0000 | [diff] [blame] | 76 | SRE_TOLOWER_HOOK lower; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 77 | } SRE_STATE; |
Guido van Rossum | b700df9 | 2000-03-31 14:59:30 +0000 | [diff] [blame] | 78 | |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 79 | typedef struct { |
| 80 | PyObject_HEAD |
| 81 | PyObject* pattern; |
Jeremy Hylton | b1aa195 | 2000-06-01 17:39:12 +0000 | [diff] [blame] | 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 |