/Modules/sre.h

http://unladen-swallow.googlecode.com/ · C++ Header · 94 lines · 61 code · 12 blank · 21 comment · 0 complexity · e9d03a8c79a84599f22ad32505ba2b49 MD5 · raw file

  1. /*
  2. * Secret Labs' Regular Expression Engine
  3. *
  4. * regular expression matching engine
  5. *
  6. * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
  7. *
  8. * See the _sre.c file for information on usage and redistribution.
  9. */
  10. #ifndef SRE_INCLUDED
  11. #define SRE_INCLUDED
  12. #include "sre_constants.h"
  13. /* size of a code word (must be unsigned short or larger, and
  14. large enough to hold a Py_UNICODE character) */
  15. #ifdef Py_UNICODE_WIDE
  16. #define SRE_CODE Py_UCS4
  17. #else
  18. #define SRE_CODE unsigned short
  19. #endif
  20. typedef struct {
  21. PyObject_VAR_HEAD
  22. Py_ssize_t groups; /* must be first! */
  23. PyObject* groupindex;
  24. PyObject* indexgroup;
  25. /* compatibility */
  26. PyObject* pattern; /* pattern source (or None) */
  27. int flags; /* flags used when compiling pattern source */
  28. PyObject *weakreflist; /* List of weak references */
  29. /* pattern code */
  30. Py_ssize_t codesize;
  31. SRE_CODE code[1];
  32. } PatternObject;
  33. #define PatternObject_GetCode(o) (((PatternObject*)(o))->code)
  34. typedef struct {
  35. PyObject_VAR_HEAD
  36. PyObject* string; /* link to the target string (must be first) */
  37. PyObject* regs; /* cached list of matching spans */
  38. PatternObject* pattern; /* link to the regex (pattern) object */
  39. Py_ssize_t pos, endpos; /* current target slice */
  40. Py_ssize_t lastindex; /* last index marker seen by the engine (-1 if none) */
  41. Py_ssize_t groups; /* number of groups (start/end marks) */
  42. Py_ssize_t mark[1];
  43. } MatchObject;
  44. typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
  45. /* FIXME: <fl> shouldn't be a constant, really... */
  46. #define SRE_MARK_SIZE 200
  47. typedef struct SRE_REPEAT_T {
  48. Py_ssize_t count;
  49. SRE_CODE* pattern; /* points to REPEAT operator arguments */
  50. void* last_ptr; /* helper to check for infinite loops */
  51. struct SRE_REPEAT_T *prev; /* points to previous repeat context */
  52. } SRE_REPEAT;
  53. typedef struct {
  54. /* string pointers */
  55. void* ptr; /* current position (also end of current slice) */
  56. void* beginning; /* start of original string */
  57. void* start; /* start of current slice */
  58. void* end; /* end of original string */
  59. /* attributes for the match object */
  60. PyObject* string;
  61. Py_ssize_t pos, endpos;
  62. /* character size */
  63. int charsize;
  64. /* registers */
  65. Py_ssize_t lastindex;
  66. Py_ssize_t lastmark;
  67. void* mark[SRE_MARK_SIZE];
  68. /* dynamically allocated stuff */
  69. char* data_stack;
  70. size_t data_stack_size;
  71. size_t data_stack_base;
  72. /* current repeat context */
  73. SRE_REPEAT *repeat;
  74. /* hooks */
  75. SRE_TOLOWER_HOOK lower;
  76. } SRE_STATE;
  77. typedef struct {
  78. PyObject_HEAD
  79. PyObject* pattern;
  80. SRE_STATE state;
  81. } ScannerObject;
  82. #endif