Пример #1
0
        private void EvaluateLook(
            int start,
            int end,
            FSA <TValue> fsa,
            LookAheadQuantifier quantifier,
            AstConcatNode concatNode,
            ORegexOptions options)
        {
            bool isBehind   = options.HasFlag(ORegexOptions.ReversePattern) ? !quantifier.IsBehind : quantifier.IsBehind;
            bool isNegative = quantifier.IsNegative;

            var condOptions = isBehind ? ORegexOptions.RightToLeft : ORegexOptions.None;
            var concat      = new AstConcatNode(concatNode.Children, concatNode.Range);
            var root        = new AstRootNode(concat,
                                              true,
                                              false,
                                              concat.Range,
                                              new[]
            {
                ORegexAstFactory <TValue> .MainCaptureName
            });
            var fa     = Create(root, condOptions);
            var oregex = new ORegex <TValue>(fa, condOptions);

            var func = new ORegexPredicateEdge <TValue>("#look", oregex, isNegative, isBehind);

            EvaluateCondition(start, end, fsa, func);
        }
Пример #2
0
        private void EvaluateConcat(int start, int end, FSA <TValue> fsa, AstConcatNode node, ORegexOptions options)
        {
            var group = node as AstGroupNode;

            if (group != null)
            {
                if (group.Quantifier != null)
                {
                    // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
                    if (group.Quantifier is CaptureQuantifier)
                    {
                        var captureQ = (CaptureQuantifier)group.Quantifier;
                        var sys      = new SystemPredicateEdge <TValue>("#capture")
                        {
                            IsCapture   = true,
                            CaptureName = captureQ.CaptureName,
                            CaptureId   = captureQ.CaptureId
                        };

                        var startTmp = CreateNewState(fsa);
                        fsa.AddTransition(start, sys, startTmp);
                        start = startTmp;
                        var endTmp = CreateNewState(fsa);
                        fsa.AddTransition(endTmp, sys, end);
                        end = endTmp;
                    }
                    else if (group.Quantifier is LookAheadQuantifier)
                    {
                        var lookQ = (LookAheadQuantifier)group.Quantifier;
                        EvaluateLook(start, end, fsa, lookQ, group, options);
                        return;
                    }
                }
            }

            var prev = start;
            int next;
            var children = node.GetChildren().ToArray();

            for (int i = 0; i < children.Length - 1; i++)
            {
                next = CreateNewState(fsa);
                Evaluate(prev, next, fsa, children[i], options);
                prev = next;
            }
            next = end;
            Evaluate(prev, next, fsa, children[children.Length - 1], options);
        }