public RegexNode MakeQuantifier(bool lazy, int min, int max) { if (min == 0 && max == 0) { return(new RegexNode(Empty, Options)); } if (min == 1 && max == 1) { return(this); } switch (NType) { case One: case Notone: case Set: MakeRep(lazy ? Onelazy : Oneloop, min, max); return(this); default: var result = new RegexNode(lazy ? Lazyloop : Loop, Options, min, max); result.AddChild(this); return(result); } }
internal RegexNode MakeQuantifier(bool lazy, int min, int max) { RegexNode result; if (min == 0 && max == 0) { return(new RegexNode(RegexNode.Empty, _options)); } if (min == 1 && max == 1) { return(this); } switch (_type) { case RegexNode.One: case RegexNode.Notone: case RegexNode.Set: MakeRep(lazy ? RegexNode.Onelazy : RegexNode.Oneloop, min, max); return(this); default: result = new RegexNode(lazy ? RegexNode.Lazyloop : RegexNode.Loop, _options, min, max); result.AddChild(this); return(result); } }
/// <summary>Performs additional optimizations on an entire tree prior to being used.</summary> internal RegexNode FinalOptimize() { RegexNode rootNode = this; // If we find backtracking construct at the end of the regex, we can instead make it non-backtracking, // since nothing would ever backtrack into it anyway. Doing this then makes the construct available // to implementations that don't support backtracking. if ((Options & RegexOptions.RightToLeft) == 0 && // only apply optimization when LTR to avoid needing additional code for the rarer RTL case (Options & RegexOptions.Compiled) != 0) // only apply when we're compiling, as that's the only time it would make a meaningful difference { RegexNode node = rootNode; while (true) { switch (node.Type) { case Oneloop: node.Type = Oneloopatomic; break; case Notoneloop: node.Type = Notoneloopatomic; break; case Setloop: node.Type = Setloopatomic; break; case Capture: case Concatenate: RegexNode existingChild = node.Child(node.ChildCount() - 1); switch (existingChild.Type) { default: node = existingChild; break; case Alternate: case Loop: case Lazyloop: var atomic = new RegexNode(Atomic, Options); atomic.AddChild(existingChild); node.ReplaceChild(node.ChildCount() - 1, atomic); break; } continue; case Atomic: node = node.Child(0); continue; } break; } } // Done optimizing. Return the final tree. return(rootNode); }
internal RegexNode MakeQuantifier(bool lazy, int min, int max) { if ((min == 0) && (max == 0)) { return(new RegexNode(0x17, this._options)); } if ((min == 1) && (max == 1)) { return(this); } switch (this._type) { case 9: case 10: case 11: this.MakeRep(lazy ? 6 : 3, min, max); return(this); } RegexNode node = new RegexNode(lazy ? 0x1b : 0x1a, this._options, min, max); node.AddChild(this); return(node); }
internal RegexNode MakeQuantifier(bool lazy, int min, int max) { RegexNode result; if (min == 0 && max == 0) return new RegexNode(RegexNode.Empty, _options); if (min == 1 && max == 1) return this; switch (_type) { case RegexNode.One: case RegexNode.Notone: case RegexNode.Set: MakeRep(lazy ? RegexNode.Onelazy : RegexNode.Oneloop, min, max); return this; default: result = new RegexNode(lazy ? RegexNode.Lazyloop : RegexNode.Loop, _options, min, max); result.AddChild(this); return result; } }
/* * Remember the pushed state (in response to a ')') */ internal void PopGroup() { _concatenation = _stack; _alternation = _concatenation._next; _group = _alternation._next; _stack = _group._next; // The first () inside a Testgroup group goes directly to the group if (_group.Type() == RegexNode.Testgroup && _group.ChildCount() == 0) { if (_unit == null) throw MakeException(SR.IllegalCondition); _group.AddChild(_unit); _unit = null; } }
internal RegexNode MakeQuantifier(bool lazy, int min, int max) { if ((min == 0) && (max == 0)) { return new RegexNode(0x17, this._options); } if ((min == 1) && (max == 1)) { return this; } switch (this._type) { case 9: case 10: case 11: this.MakeRep(lazy ? 6 : 3, min, max); return this; } RegexNode node = new RegexNode(lazy ? 0x1b : 0x1a, this._options, min, max); node.AddChild(this); return node; }