Home | History | Annotate | Download | only in re2

Lines Matching full:regexp

10 #include "re2/regexp.h"
15 // Parses the regexp src and then simplifies it and sets *dst to the
18 bool Regexp::SimplifyRegexp(const StringPiece& src, ParseFlags flags,
21 Regexp* re = Parse(src, flags, status);
24 Regexp* sre = re->Simplify();
41 // is this Regexp* simple?
42 bool Regexp::ComputeSimple() {
43 Regexp** subs;
102 // The child_args are simplified Regexp*s.
103 class SimplifyWalker : public Regexp::Walker<Regexp*> {
106 virtual Regexp* PreVisit(Regexp* re, Regexp* parent_arg, bool* stop);
107 virtual Regexp* PostVisit(Regexp* re,
108 Regexp* parent_arg,
109 Regexp* pre_arg,
110 Regexp** child_args, int nchild_args);
111 virtual Regexp* Copy(Regexp* re);
112 virtual Regexp* ShortVisit(Regexp* re, Regexp* parent_arg);
118 // Creates a concatenation of two Regexp, consuming refs to re1 and re2.
120 static Regexp* Concat2(Regexp* re1, Regexp* re2, Regexp::ParseFlags flags);
123 // Returns a new regexp. Does not edit re. Does not consume reference to re.
125 static Regexp* SimplifyRepeat(Regexp* re, int min, int max,
126 Regexp::ParseFlags parse_flags);
131 static Regexp* SimplifyCharClass(Regexp* re);
136 // Simplifies a regular expression, returning a new regexp.
137 // The new regexp uses traditional Unix egrep features only,
139 // Otherwise, no POSIX or Perl additions. The new regexp
145 Regexp* Regexp::Simplify() {
154 Regexp* SimplifyWalker::Copy(Regexp* re) {
158 Regexp* SimplifyWalker::ShortVisit(Regexp* re, Regexp* parent_arg) {
165 Regexp* SimplifyWalker::PreVisit(Regexp* re, Regexp* parent_arg, bool* stop) {
173 Regexp* SimplifyWalker::PostVisit(Regexp* re,
174 Regexp* parent_arg,
175 Regexp* pre_arg,
176 Regexp** child_args,
201 Regexp** subs = re->sub();
203 Regexp* sub = subs[i];
204 Regexp* newsub = child_args[i];
212 Regexp* newsub = child_args[i];
218 Regexp* nre = new Regexp(re->op(), re->parse_flags());
220 Regexp** nre_subs = nre->sub();
228 Regexp* newsub = child_args[0];
234 Regexp* nre = new Regexp(kRegexpCapture, re->parse_flags());
245 Regexp* newsub = child_args[0];
263 Regexp* nre = new Regexp(re->op(), re->parse_flags());
271 Regexp* newsub = child_args[0];
277 Regexp* nre = SimplifyRepeat(newsub, re->min_, re->max_,
285 Regexp* nre = SimplifyCharClass(re);
295 // Creates a concatenation of two Regexp, consuming refs to re1 and re2.
296 // Returns a new Regexp, handing the ref to the caller.
297 Regexp* SimplifyWalker::Concat2(Regexp* re1, Regexp* re2,
298 Regexp::ParseFlags parse_flags) {
299 Regexp* re = new Regexp(kRegexpConcat, parse_flags);
301 Regexp** subs = re->sub();
308 // Returns a new regexp. Does not edit re. Does not consume reference to re.
312 // but in the Regexp* representation, both (x) are marked as $1.
313 Regexp* SimplifyWalker::SimplifyRepeat(Regexp* re, int min, int max,
314 Regexp::ParseFlags f) {
319 return Regexp::Star(re->Incref(), f);
323 return Regexp::Plus(re->Incref(), f);
326 Regexp* nre = new Regexp(kRegexpConcat, f);
329 Regexp** nre_subs = nre->sub();
332 nre_subs[min-1] = Regexp::Plus(re->Incref(), f);
338 return new Regexp(kRegexpEmptyMatch, f);
349 Regexp* nre = NULL;
351 nre = new Regexp(kRegexpConcat, f);
353 Regexp** nre_subs = nre->sub();
360 Regexp* suf = Regexp::Quest(re->Incref(), f);
362 suf = Regexp::Quest(Concat2(re->Incref(), suf, f), f);
373 return new Regexp(kRegexpNoMatch, f);
381 Regexp* SimplifyWalker::SimplifyCharClass(Regexp* re) {
386 return new Regexp(kRegexpNoMatch, re->parse_flags());
388 return new Regexp(kRegexpAnyChar, re->parse_flags());