aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/PosRegExp.h
blob: b915b1ed49cccb4ce557571273c157cc9a7ebf79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef POSREGEXP_H
#define POSREGEXP_H

#define MatchesNum 0x10

enum EOps
{
  ReBlockOps = 0x1000,
  ReMul,              // *
  RePlus,             // +
  ReQuest,            // ?
  ReNGMul,            // *?
  ReNGPlus,           // +?
  ReNGQuest,          // ??
  ReRangeN,           // {n,}
  ReRangeNM,          // {n,m}
  ReNGRangeN,         // {n,}?
  ReNGRangeNM,        // {n,m}?
  ReOr,               // |
  ReBehind  = 0x1100, // ?#n
  ReNBehind = 0x1200, // ?~n
  ReAhead   = 0x1300, // ?=
  ReNAhead  = 0x1400, // ?!

  ReSymbolOps = 0x2000,
  ReEmpty,
  ReSymb,             // a b \W \s ...
  ReEnum,             // []
  ReNEnum,            // [^]
  ReBrackets,         // (...)
  ReBkTrace = 0x2100, // \yN
  ReBkBrack = 0x2200 // \N
};

enum ESymbols
{
  ReAnyChr = 0x4000,  // .
  ReSoL,              // ^
  ReEoL,              // $
  ReDigit,            // \d
  ReNDigit,           // \D
  ReWordSymb,         // \w
  ReNWordSymb,        // \W
  ReWSpace,           // \s
  ReNWSpace,          // \S
  ReUCase,            // \u
  ReNUCase ,          // \l
  ReWBound,           // \b
  ReNWBound,          // \B
  RePreNW,            // \c
  ReStart,            // \m
  ReEnd,              // \M

  ReChr    = 0x0      // Char in Lower Byte
};
enum ETempSymb
{
  ReTemp = 0x7000,
  ReLBrack, ReRBrack,
  ReEnumS, ReEnumE, ReNEnumS,
  ReRangeS, ReRangeE, ReNGRangeE, ReFrToEnum
};

#define BackSlash '\\'

typedef union SCharData
{
  int  IArr[8];
  char CArr[32];
  void SetBit(unsigned char Bit);
  void ClearBit(unsigned char Bit);
  bool GetBit(unsigned char Bit);
} *PCharData;

typedef struct SRegInfo
{
  SRegInfo();
  ~SRegInfo();

  EOps   Op;
  union{
    SRegInfo *Param;
    int Symb;
    PCharData ChrClass;
  }un;
  int s,e;
  SRegInfo *Parent;
  SRegInfo *Next;
} *PRegInfo;

typedef struct SMatches
{
  int s[MatchesNum];
  int e[MatchesNum];
  int CurMatch;
} *PMatches;

typedef class PosRegExp
{
  PRegInfo Info;
  PMatches BkTrace;
  bool NoCase,Extend,NoMoves;
  bool Error;
  int  *Exprn;
  int  posParse;
  int  posEnd,posStart;
  int  posBkStr;
  int  FirstChar;

  bool SetExprLow(const char *Expr);
  bool SetStructs(PRegInfo &Info,int st,int end);
  void Optimize();
  bool CheckSymb(int Symb,bool Inc);
  bool LowParse(PRegInfo Re);
  bool LowParseRe(PRegInfo &Next);
  bool LowCheckNext(PRegInfo Re);
  bool ParseRe(int posStr);
  bool QuickCheck();
public:
  PMatches Matches;
  int Ok, CurMatch;

  void *param;
  char (*CharAt)(int pos, void *param);

  PosRegExp();
  ~PosRegExp();

  bool isok();
  bool SetNoMoves(bool Moves);
  bool SetBkTrace(int posStr,PMatches Trace);
  bool SetExpr(const char *Expr);
  bool Parse(int posStr, int posStop, PMatches Mtch);
  bool Parse(int posStr,int posSol, int posEol, PMatches Mtch, int Moves = -1);
  bool Evaluate(char *Expr, int posStr, PMatches Mtch, char **Res);
} *PPosRegExp;

#endif /* POSREGEXP_H */