Example #1
0
        private static AstGroupNode CreateGroup(IParseTree node, ORegexAstFactoryArgs <TValue> args)
        {
            var predicate = node.GetChild(0).GetText();
            var inner     = Create(node.GetChild(1), args);

            var children = new List <AstNodeBase>();

            if (inner is AstConcatNode)
            {
                children.AddRange(inner.GetChildren());
            }
            else
            {
                children.Add(inner);
            }

            QuantifierBase quantifier = null;

            if (CaptureQuantifier.IsCapture(predicate))
            {
                var cq = new CaptureQuantifier(predicate, args.CaptureGroupNames.Count);
                args.CaptureGroupNames.Add(cq.CaptureName);
                quantifier = cq;
            }
            else if (LookAheadQuantifier.IsLook(predicate))
            {
                quantifier = new LookAheadQuantifier(predicate);
            }
            return(new AstGroupNode(children, quantifier, new Range(node)));
        }
Example #2
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);
        }