Ejemplo n.º 1
0
        private QuantifierNode CreateDefaultQuantifier(string contents)
        {
            var node = new QuantifierNode();

            node.InputContents.ConnectedNode = new FakeNodeOutput(contents);
            return(node);
        }
Ejemplo n.º 2
0
        public string GetSuffix_BasicModes_ReturnsSuffix(Reps mode)
        {
            var node = new QuantifierNode();

            node.InputCount.Value = mode;
            return(IQuantifiableNode.GetSuffix(node));
        }
Ejemplo n.º 3
0
        private static QuantifierNode CreateWithRepetitions(Reps repetitions)
        {
            var node = new QuantifierNode();

            node.InputCount.Value = repetitions;
            return(node);
        }
Ejemplo n.º 4
0
        /// <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);
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        public string GetSuffix_Number_ReturnsSuffix(int?number)
        {
            var node = new QuantifierNode();

            node.InputCount.Value  = Reps.Number;
            node.InputNumber.Value = number;
            return(IQuantifiableNode.GetSuffix(node));
        }
Ejemplo n.º 7
0
        private static QuantifierNode CreateWithNumber(int number)
        {
            var node = new QuantifierNode();

            node.InputCount.Value  = Reps.Number;
            node.InputNumber.Value = number;
            return(node);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
 private static QuantifierNode WithSearchType(this QuantifierNode node, QuantifierNode.SearchMode searchType)
 {
     node.InputSearchType.Value = searchType;
     return(node);
 }