home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Modules / sre.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  2.3 KB  |  86 lines

  1. /*
  2.  * Secret Labs' Regular Expression Engine
  3.  *
  4.  * regular expression matching engine
  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.  
  16. /* size of a code word (must be unsigned short or larger) */
  17. #define SRE_CODE unsigned short
  18.  
  19. typedef struct {
  20.     PyObject_VAR_HEAD
  21.     int groups;
  22.     PyObject* groupindex;
  23.     PyObject* indexgroup;
  24.     /* compatibility */
  25.     PyObject* pattern; /* pattern source (or None) */
  26.     int flags; /* flags used when compiling pattern source */
  27.     /* pattern code */
  28.     SRE_CODE code[1];
  29. } PatternObject;
  30.  
  31. #define PatternObject_GetCode(o) (((PatternObject*)(o))->code)
  32.  
  33. typedef struct {
  34.     PyObject_VAR_HEAD
  35.     PyObject* string; /* link to the target string */
  36.     PyObject* regs; /* cached list of matching spans */
  37.     PatternObject* pattern; /* link to the regex (pattern) object */
  38.     int pos, endpos; /* current target slice */
  39.     int lastindex; /* last index marker seen by the engine (-1 if none) */
  40.     int groups; /* number of groups (start/end marks) */
  41.     int mark[1];
  42. } MatchObject;
  43.  
  44. typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
  45.  
  46. /* FIXME: <fl> shouldn't be a constant, really... */
  47. #define SRE_MARK_SIZE 200
  48.  
  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.  
  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 */
  61.     /* attributes for the match object */
  62.     PyObject* string;
  63.     int pos, endpos;
  64.     /* character size */
  65.     int charsize;
  66.     /* registers */
  67.     int lastindex;
  68.     int lastmark;
  69.     void* mark[SRE_MARK_SIZE];
  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 */
  75.     /* hooks */
  76.     SRE_TOLOWER_HOOK lower;
  77. } SRE_STATE;
  78.  
  79. typedef struct {
  80.     PyObject_HEAD
  81.     PyObject* pattern;
  82.     SRE_STATE state;
  83. } ScannerObject;
  84.  
  85. #endif
  86.