/*1* Secret Labs' Regular Expression Engine2*3* regular expression matching engine4*5* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.6*7* See the sre.c file for information on usage and redistribution.8*/910#ifndef SRE_INCLUDED11#define SRE_INCLUDED1213#include "sre_constants.h"1415/* size of a code word (must be unsigned short or larger, and16large enough to hold a UCS4 character) */17#define SRE_CODE Py_UCS418#if SIZEOF_SIZE_T > 419# define SRE_MAXREPEAT (~(SRE_CODE)0)20# define SRE_MAXGROUPS ((SRE_CODE)INT32_MAX / 2)21#else22# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX)23# define SRE_MAXGROUPS ((SRE_CODE)PY_SSIZE_T_MAX / SIZEOF_VOID_P / 2)24#endif2526typedef struct {27PyObject_VAR_HEAD28Py_ssize_t groups; /* must be first! */29PyObject* groupindex; /* dict */30PyObject* indexgroup; /* tuple */31/* compatibility */32PyObject* pattern; /* pattern source (or None) */33int flags; /* flags used when compiling pattern source */34PyObject *weakreflist; /* List of weak references */35int isbytes; /* pattern type (1 - bytes, 0 - string, -1 - None) */36/* pattern code */37Py_ssize_t codesize;38SRE_CODE code[1];39} PatternObject;4041#define PatternObject_GetCode(o) (((PatternObject*)(o))->code)4243typedef struct {44PyObject_VAR_HEAD45PyObject* string; /* link to the target string (must be first) */46PyObject* regs; /* cached list of matching spans */47PatternObject* pattern; /* link to the regex (pattern) object */48Py_ssize_t pos, endpos; /* current target slice */49Py_ssize_t lastindex; /* last index marker seen by the engine (-1 if none) */50Py_ssize_t groups; /* number of groups (start/end marks) */51Py_ssize_t mark[1];52} MatchObject;5354typedef struct {55PyObject_VAR_HEAD56Py_ssize_t chunks; /* the number of group references and non-NULL literals57* self->chunks <= 2*Py_SIZE(self) + 1 */58PyObject *literal;59struct {60Py_ssize_t index;61PyObject *literal; /* NULL if empty */62} items[0];63} TemplateObject;6465typedef struct SRE_REPEAT_T {66Py_ssize_t count;67const SRE_CODE* pattern; /* points to REPEAT operator arguments */68const void* last_ptr; /* helper to check for infinite loops */69struct SRE_REPEAT_T *prev; /* points to previous repeat context */70} SRE_REPEAT;7172typedef struct {73/* string pointers */74const void* ptr; /* current position (also end of current slice) */75const void* beginning; /* start of original string */76const void* start; /* start of current slice */77const void* end; /* end of original string */78/* attributes for the match object */79PyObject* string;80Py_buffer buffer;81Py_ssize_t pos, endpos;82int isbytes;83int charsize; /* character size */84int match_all;85int must_advance;86/* marks */87int lastmark;88int lastindex;89const void** mark;90/* dynamically allocated stuff */91char* data_stack;92size_t data_stack_size;93size_t data_stack_base;94/* current repeat context */95SRE_REPEAT *repeat;96} SRE_STATE;9798typedef struct {99PyObject_HEAD100PyObject* pattern;101SRE_STATE state;102int executing;103} ScannerObject;104105#endif106107108