Exemplo n.º 1
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder();

            //check whether nothing is connected to this node.
            if (PreviousNode is null)
            {
                builder.Append("Nothing connected to Output node", this);
                return(builder);
            }
            builder.Append(Previous.Value);

            //Prefix
            switch (InputStartsAt.Value)
            {
            case Mode.StartLine: builder.Prepend("^", this); break;

            case Mode.WordBound: builder.Prepend("\\b", this); break;
            }

            //Suffix
            switch (InputEndsAt.Value)
            {
            case Mode.EndLine: builder.Append("$", this); break;

            case Mode.WordBound: builder.Append("\\b", this); break;
            }

            if (PreviousNode is OrNode)
            {
                builder.StripNonCaptureGroup();
            }
            return(builder);
        }
Exemplo n.º 2
0
        private void AddSign(NodeResultBuilder builder)
        {
            switch (InputSign.Value)
            {
            case SignType.Compulsory:
                builder.Prepend("[-+]", this); break;

            case SignType.Optional:
                builder.Prepend("[-+]?", this); break;

            case SignType.Negative:
                builder.Prepend("-", this); break;
            }
        }
Exemplo n.º 3
0
        protected override NodeResultBuilder GetValue()
        {
            //Expression to match the number, without sign
            string number = InputLimitBy.Value switch
            {
                LimitType.Value => GetIntegerRangeRegex(InputValueRange.Min ?? 0, InputValueRange.Max ?? 0),
                LimitType.Digits => (InputDigitRange.Min ?? 0) == InputDigitRange.Max ?
                $"\\d{{{InputDigitRange.Min}}}" :
                $"\\d{{{InputDigitRange.Min ?? 0},{InputDigitRange.Max}}}",
                LimitType.Nothing => "\\d+",
                _ => "\\d+",
            };
            var builder = new NodeResultBuilder(number, this);

            //Add non-capturing group to make the alternation work
            if (number.Contains('|'))
            {
                builder.AddNonCaptureGroup(this);
            }

            if (InputLeadingZeros.Checked)
            {
                builder.Prepend("0*", this);
            }

            AddSign(builder);

            return(builder);
        }
Exemplo n.º 4
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder(Input.Value);

            if (Input.ConnectedNode is OrNode ||
                Input.ConnectedNode is IntegerNode
                )
            {
                builder.StripNonCaptureGroup();
            }

            string prefix = InputGroupType.Value switch
            {
                GroupTypes.capturing => "(",
                GroupTypes.nonCapturing => "(?:",
                GroupTypes.named => $"(?<{GroupName.GetValue()}>",
                GroupTypes.atomic => $"(?>",
                GroupTypes.custom => "(" + CustomPrefix.GetValue(),
                _ => "",
            };

            builder.Prepend(prefix, this);
            builder.Append(")", this);
            return(builder);
        }
Exemplo n.º 5
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder(InputContents.Value);

            string whitespace = InputAllowWhitespace.Checked ? "\\s*?" : "";

            string separator = InputSeparator.Value;

            if (!InputAllowRegex.Checked)
            {
                separator = separator.EscapeCharacters(SeparatorCharsToEscape);
            }

            int    minReps    = InputListLength.Min ?? 0;
            int?   maxReps    = InputListLength.Max;
            string quantifier = (min : minReps, max : maxReps) switch
            {
                (0, 2) => "?",
                (1, 2) => "?",
                (0, null) => "*",
                (1, null) => "*",
                (2, null) => "+",
                (0, int max) => $"{{{0},{max - 1}}}",
                var range when range.min == range.max => $"{{{range.min - 1}}}",
                var range => $"{{{range.min - 1},{range.max - 1}}}"
            };

            if (InputLazyQuantifier.Checked)
            {
                quantifier += "?";
            }

            string suffix = ")" + quantifier;

            if (minReps <= 0)
            {
                builder.Prepend("(?:", this);
                suffix += ")?";
            }

            builder.Append("(?:" + separator + whitespace, this);
            builder.Append(InputContents.Value);
            builder.Append(suffix, this);

            return(builder);
        }
Exemplo n.º 6
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder(InputContents.Value);

            //Simplify IntegerNode if needed
            if (InputContents.ConnectedNode is IntegerNode)
            {
                builder.StripNonCaptureGroup();
            }

            string suffix = "";
            string prefix = "";

            //Surround with non-capturing group if necessary
            if (InputContents.ConnectedNode is Node _node &&
                RequiresGroupToQuantify(_node))
            {
                prefix += "(?:";
                suffix += ")";
            }

            //Add quantifier
            suffix += GetSuffix(this);

            //Add modifier
            if (InputCount.Value != Reps.Number)
            {
                if (InputSearchType.Value == SearchMode.Lazy)
                {
                    suffix += "?";
                }
                else if (InputSearchType.Value == SearchMode.Possessive)
                {
                    suffix += ")";
                    prefix  = "(?>" + prefix;
                }
            }

            builder.Prepend(prefix, this);
            builder.Append(suffix, this);
            return(builder);
        }
Exemplo n.º 7
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder(InputContents.Value);

            string suffix = "";
            string prefix = "";

            //Surround with non-capturing group if necessary
            if (InputContents.ConnectedNode is Node _node &&
                QuantifierNode.RequiresGroupToQuantify(_node))
            {
                prefix += "(?:";
                suffix += ")";
            }

            //Add quantifier
            suffix += "?";

            builder.Prepend(prefix, this);
            builder.Append(suffix, this);
            return(builder);
        }
Exemplo n.º 8
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder(Input.Value);

            if (Input.ConnectedNode is OrNode)
            {
                builder.StripNonCaptureGroup();
            }

            string prefix = InputGroupType.Value switch
            {
                Types.lookahead => "(?=",
                Types.lookbehind => "(?<=",
                Types.lookaheadNeg => "(?!",
                Types.lookbehindNeg => "(?<!",
                _ => "",
            };

            builder.Prepend(prefix, this);
            builder.Append(")", this);
            return(builder);
        }
Exemplo n.º 9
0
        protected override NodeResultBuilder GetValue()
        {
            var builder = new NodeResultBuilder();

            string open  = InputOpenBracket.Value;
            string close = InputCloseBracket.Value;

            string openEscaped  = open;
            string closeEscaped = close;

            if (!InputRegexInBrackets.Checked)
            {
                openEscaped  = open.EscapeSpecialCharacters();
                closeEscaped = close.EscapeSpecialCharacters();
            }

            //Get expression for 'anything other than brackets'
            string notBrackets;

            if (open.Length <= 1 && close.Length <= 1)
            {
                //Use inverted CharSet if brackets are single chars
                notBrackets = $"[^{open.EscapeCharacters("[]")}{close.EscapeCharacters("[]")}]";
            }
            else
            {
                //Use negative lookahead if brackets are expressions
                notBrackets = $"(?!{openEscaped}|{closeEscaped}).";
            }

            NodeResult betweenRec = InputContents.Connected ?
                                    InputContents.Value :
                                    new NodeResult(notBrackets, this);

            string groupName        = InputGroupName.Value;
            string captureGroupName = InputCaptureName.Value;

            string openingGroup = InputNoBacktracking.Checked ?
                                  "(?>" :
                                  "(?:";

            //Construct output
            builder.Append(openingGroup, this);
            {
                builder.Append($"(?<{groupName}>{openEscaped})", this);
                builder.Append("|", this);
                builder.Append($"(?<{captureGroupName}-{groupName}>{closeEscaped})", this);
                builder.Append("|", this);
                builder.Append(betweenRec);
            }
            builder.Append(")+", this);
            builder.Append($"(?({groupName})(?!))", this);

            if (InputEnclosingBrackets.Checked)
            {
                builder.Prepend(openEscaped, this);
                builder.Append(closeEscaped, this);
            }

            return(builder);
        }