2000-03-31 16:59:30 +02:00
|
|
|
/*
|
|
|
|
* Secret Labs' Regular Expression Engine
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* simple regular expression matching engine
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
|
|
|
|
*
|
|
|
|
* See the _sre.c file for information on usage and redistribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRE_INCLUDED
|
|
|
|
#define SRE_INCLUDED
|
|
|
|
|
|
|
|
#include "sre_constants.h"
|
|
|
|
|
2000-06-29 10:55:54 +02:00
|
|
|
/* size of a code word (must be unsigned short or larger) */
|
|
|
|
#define SRE_CODE unsigned short
|
|
|
|
|
2000-03-31 16:59:30 +02:00
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
PyObject* code; /* link to the code string object */
|
|
|
|
int groups;
|
|
|
|
PyObject* groupindex;
|
2000-06-01 19:39:12 +02:00
|
|
|
/* compatibility */
|
|
|
|
PyObject* pattern; /* pattern source (or None) */
|
|
|
|
int flags; /* flags used when compiling pattern source */
|
2000-03-31 16:59:30 +02:00
|
|
|
} PatternObject;
|
|
|
|
|
2000-06-01 19:39:12 +02:00
|
|
|
#define PatternObject_GetCode(o)\
|
|
|
|
((void*) PyString_AS_STRING(((PatternObject*)(o))->code))
|
2000-03-31 16:59:30 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
PyObject* string; /* link to the target string */
|
|
|
|
PatternObject* pattern; /* link to the regex (pattern) object */
|
|
|
|
int groups; /* number of groups (start/end marks) */
|
|
|
|
int mark[2];
|
|
|
|
} MatchObject;
|
|
|
|
|
2000-06-29 10:55:54 +02:00
|
|
|
typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* stack elements */
|
|
|
|
SRE_CODE* pattern;
|
|
|
|
void* ptr;
|
|
|
|
} SRE_STACK;
|
|
|
|
|
2000-06-29 18:57:40 +02:00
|
|
|
/* FIXME: <fl> shouldn't be a constant, really... */
|
|
|
|
#define SRE_MARK_SIZE 200
|
|
|
|
|
2000-06-01 19:39:12 +02:00
|
|
|
typedef struct {
|
|
|
|
/* string pointers */
|
|
|
|
void* ptr; /* current position (also end of current slice) */
|
|
|
|
void* beginning; /* start of original string */
|
|
|
|
void* start; /* start of current slice */
|
|
|
|
void* end; /* end of original string */
|
|
|
|
/* character size */
|
|
|
|
int charsize;
|
|
|
|
/* registers */
|
2000-06-29 10:55:54 +02:00
|
|
|
int lastmark;
|
2000-06-29 18:57:40 +02:00
|
|
|
void* mark[SRE_MARK_SIZE];
|
2000-06-01 19:39:12 +02:00
|
|
|
/* backtracking stack */
|
2000-06-29 10:55:54 +02:00
|
|
|
SRE_STACK* stack;
|
2000-06-01 19:39:12 +02:00
|
|
|
int stacksize;
|
|
|
|
int stackbase;
|
2000-06-29 10:55:54 +02:00
|
|
|
/* hooks */
|
2000-06-29 14:48:37 +02:00
|
|
|
SRE_TOLOWER_HOOK lower;
|
2000-06-01 19:39:12 +02:00
|
|
|
} SRE_STATE;
|
2000-03-31 16:59:30 +02:00
|
|
|
|
2000-06-01 19:39:12 +02:00
|
|
|
typedef struct {
|
2000-06-29 18:57:40 +02:00
|
|
|
/* scanner (internal helper object) */
|
2000-06-01 19:39:12 +02:00
|
|
|
PyObject_HEAD
|
|
|
|
PyObject* pattern;
|
|
|
|
PyObject* string;
|
|
|
|
SRE_STATE state;
|
2000-06-29 18:57:40 +02:00
|
|
|
} ScannerObject;
|
2000-06-01 19:39:12 +02:00
|
|
|
|
|
|
|
#endif
|