private QuantifierNode CreateDefaultQuantifier(string contents) { var node = new QuantifierNode(); node.InputContents.ConnectedNode = new FakeNodeOutput(contents); return(node); }
public string GetSuffix_BasicModes_ReturnsSuffix(Reps mode) { var node = new QuantifierNode(); node.InputCount.Value = mode; return(IQuantifiableNode.GetSuffix(node)); }
private static QuantifierNode CreateWithRepetitions(Reps repetitions) { var node = new QuantifierNode(); node.InputCount.Value = repetitions; return(node); }
/// <summary> /// Create a quantifier node in response to a '*', '+' or '?'. The quantifier node will replace the last concatenation item in the current group. /// Throws an exception if there are no concatenation items in the current group or if the previous node was a quantifier. /// </summary> private void ParseQuantifierAlias(char ch) { var currentConcatenation = CurrentConcatenation(); // Don't allow empty quantifiers if (!currentConcatenation.Any()) { throw MakeException(RegexParseError.EmptyQuantifier); } // Don't allow nested quantifiers if (_previousWasQuantifier) { throw MakeException(RegexParseError.NestedQuantifier); } RegexNode previousNode = currentConcatenation.Last(); QuantifierNode quantifier = ch switch { '*' => new QuantifierStarNode(previousNode), '+' => new QuantifierPlusNode(previousNode), '?' => new QuantifierQuestionMarkNode(previousNode), _ => throw MakeException(RegexParseError.InternalError) }; // Quantifier followed by '?' is a lazy quantifier if (IsLazy()) { currentConcatenation[^ 1] = new LazyNode(quantifier);
private static Node AttachToNode(this QuantifierNode quant, Node contents) { switch (contents) { case IQuantifiableNode child when contents.PreviousNode is null && quant.InputSearchType.Value == QuantifierNode.SearchMode.Greedy: //Transfer properties to child node if Quantifiable child.InputCount.Value = quant.InputCount.Value; child.InputRange.Min = quant.InputRange.Min; child.InputRange.Max = quant.InputRange.Max; child.InputNumber.Value = quant.InputNumber.Value; return(child as Node); case GroupNode child when child.PreviousNode is null && child.InputGroupType.Value == GroupNode.GroupTypes.nonCapturing: //Discard unneseccary non-capturing group quant.InputContents.ConnectedNode = child.Input.ConnectedNode; return(quant); default: quant.InputContents.ConnectedNode = contents; return(quant); } }
public string GetSuffix_Number_ReturnsSuffix(int?number) { var node = new QuantifierNode(); node.InputCount.Value = Reps.Number; node.InputNumber.Value = number; return(IQuantifiableNode.GetSuffix(node)); }
private static QuantifierNode CreateWithNumber(int number) { var node = new QuantifierNode(); node.InputCount.Value = Reps.Number; node.InputNumber.Value = number; return(node); }
public string GetSuffix_Range_ReturnsSuffix(int?min, int?max) { var node = new QuantifierNode(); node.InputCount.Value = Reps.Range; node.InputRange.Min = min; node.InputRange.Max = max; return(IQuantifiableNode.GetSuffix(node)); }
private static QuantifierNode CreateWithRange(int min, int?max) { var node = new QuantifierNode(); node.InputCount.Value = Reps.Range; node.InputRange.Min = min; node.InputRange.Max = max; return(node); }
public string GetOutput_UngroupedContents_ReturnsContentsGroupedWithAsterisk(string contents) { var node = new QuantifierNode(); var input = new TextNode(); input.Input.Contents = contents; input.InputEscapeSpecials.IsChecked = false; node.InputContents.ConnectedNode = input; node.InputSearchType.Value = QuantifierNode.SearchMode.Greedy; return(node.CachedOutput.Expression); }
private static Node AttachToNode(this QuantifierNode quant, Node contents) { switch (contents) { case IQuantifiableNode child when contents.PreviousNode is null && quant.InputSearchType.Value == QuantifierNode.SearchMode.Greedy: child.InputCount.Value = quant.InputCount.Value; child.InputMin.InputContents = quant.InputMin.InputContents; child.InputMax.InputContents = quant.InputMax.InputContents; child.InputNumber.InputContents = quant.InputNumber.InputContents; return(child as Node); case GroupNode child when child.PreviousNode is null && child.InputGroupType.Value == GroupNode.GroupTypes.nonCapturing: quant.InputContents.ConnectedNode = child.Input.ConnectedNode; return(quant); default: quant.InputContents.ConnectedNode = contents; return(quant); } }
private static QuantifierNode WithSearchType(this QuantifierNode node, QuantifierNode.SearchMode searchType) { node.InputSearchType.Value = searchType; return(node); }