blob: bf58eb5434501b95f9ac235a61b82c06319e060a [file] [log] [blame]
Guido van Rossumb700df92000-03-31 14:59:30 +00001/*
2 * Secret Labs' Regular Expression Engine
Guido van Rossumb700df92000-03-31 14:59:30 +00003 *
Fredrik Lundh80946112000-06-29 18:03:25 +00004 * regular expression matching engine
Guido van Rossumb700df92000-03-31 14:59:30 +00005 *
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 Lundh102f3ad2000-06-29 08:55:54 +000016/* size of a code word (must be unsigned short or larger) */
17#define SRE_CODE unsigned short
18
Guido van Rossumb700df92000-03-31 14:59:30 +000019typedef struct {
Fredrik Lundh6f013982000-07-03 18:44:21 +000020 PyObject_VAR_HEAD
Guido van Rossumb700df92000-03-31 14:59:30 +000021 int groups;
22 PyObject* groupindex;
Fredrik Lundhc2301732000-07-02 22:25:39 +000023 PyObject* indexgroup;
Jeremy Hyltonb1aa1952000-06-01 17:39:12 +000024 /* compatibility */
25 PyObject* pattern; /* pattern source (or None) */
26 int flags; /* flags used when compiling pattern source */
Fredrik Lundh6f013982000-07-03 18:44:21 +000027 /* pattern code */
28 SRE_CODE code[1];
Guido van Rossumb700df92000-03-31 14:59:30 +000029} PatternObject;
30
Fredrik Lundh6f013982000-07-03 18:44:21 +000031#define PatternObject_GetCode(o) (((PatternObject*)(o))->code)
Guido van Rossumb700df92000-03-31 14:59:30 +000032
33typedef struct {
Fredrik Lundh6f013982000-07-03 18:44:21 +000034 PyObject_VAR_HEAD
Guido van Rossumb700df92000-03-31 14:59:30 +000035 PyObject* string; /* link to the target string */
Fredrik Lundh8a3ebf82000-07-23 21:46:17 +000036 PyObject* regs; /* cached list of matching spans */
Guido van Rossumb700df92000-03-31 14:59:30 +000037 PatternObject* pattern; /* link to the regex (pattern) object */
Fredrik Lundh6f013982000-07-03 18:44:21 +000038 int pos, endpos; /* current target slice */
39 int lastindex; /* last index marker seen by the engine (-1 if none) */
Guido van Rossumb700df92000-03-31 14:59:30 +000040 int groups; /* number of groups (start/end marks) */
Fredrik Lundh6f013982000-07-03 18:44:21 +000041 int mark[1];
Guido van Rossumb700df92000-03-31 14:59:30 +000042} MatchObject;
43
Fredrik Lundh102f3ad2000-06-29 08:55:54 +000044typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
45
Fredrik Lundhbe2211e2000-06-29 16:57:40 +000046/* FIXME: <fl> shouldn't be a constant, really... */
47#define SRE_MARK_SIZE 200
48
Fredrik Lundh29c4ba92000-08-01 18:20:07 +000049typedef 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 Hyltonb1aa1952000-06-01 17:39:12 +000055typedef 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 Lundh8a3ebf82000-07-23 21:46:17 +000061 /* attributes for the match object */
62 PyObject* string;
63 int pos, endpos;
Jeremy Hyltonb1aa1952000-06-01 17:39:12 +000064 /* character size */
65 int charsize;
66 /* registers */
Fredrik Lundh6f013982000-07-03 18:44:21 +000067 int lastindex;
Fredrik Lundh102f3ad2000-06-29 08:55:54 +000068 int lastmark;
Fredrik Lundhbe2211e2000-06-29 16:57:40 +000069 void* mark[SRE_MARK_SIZE];
Fredrik Lundh29c4ba92000-08-01 18:20:07 +000070 /* 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 Lundh102f3ad2000-06-29 08:55:54 +000075 /* hooks */
Fredrik Lundhb389df32000-06-29 12:48:37 +000076 SRE_TOLOWER_HOOK lower;
Jeremy Hyltonb1aa1952000-06-01 17:39:12 +000077} SRE_STATE;
Guido van Rossumb700df92000-03-31 14:59:30 +000078
Jeremy Hyltonb1aa1952000-06-01 17:39:12 +000079typedef struct {
80 PyObject_HEAD
81 PyObject* pattern;
Jeremy Hyltonb1aa1952000-06-01 17:39:12 +000082 SRE_STATE state;
Fredrik Lundhbe2211e2000-06-29 16:57:40 +000083} ScannerObject;
Jeremy Hyltonb1aa1952000-06-01 17:39:12 +000084
85#endif