コード例 #1
0
ファイル: ORegex.cs プロジェクト: mpvyard/ORegex
        private IEnumerable <OMatch <TValue> > GetAllMathes(TValue[] values, int startIndex = -1)
        {
            var handler = new SequenceHandler <TValue>(values)
            {
                Reverse = Options.HasFlag(ORegexOptions.ReverseSequence)
            };

            startIndex = GetStartIndex(handler, startIndex);

            var captureTable = new OCaptureTable <TValue>(_fa.CaptureNames);

            for (int i = startIndex; i <= handler.Count; i++)
            {
                Range range;
                if (_fa.TryRun(handler, i, captureTable, out range))
                {
                    bool beginMatched = range.Index == startIndex;
                    bool endMatched   = range.RightIndex == handler.Count;

                    if (!_fa.ExactBegin && !_fa.ExactEnd ||
                        !(beginMatched ^ _fa.ExactBegin) && !(endMatched ^ _fa.ExactEnd))
                    {
                        var match = new OMatch <TValue>(handler, captureTable, range);
                        captureTable.Add(0, match);
                        yield return(match);
                    }
                    captureTable = new OCaptureTable <TValue>(_fa.CaptureNames);
                    i           += range.Length == 0 ? 0 : range.Length - 1;
                }
                if (_fa.ExactBegin)
                {
                    break;
                }
            }
        }
コード例 #2
0
ファイル: FSAFactory.cs プロジェクト: mpvyard/ORegex
        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);
        }
コード例 #3
0
ファイル: FSAFactory.cs プロジェクト: mpvyard/ORegex
        public FiniteAutomaton <TValue> Create(AstRootNode root, ORegexOptions options)
        {
            var nfa = CreateRawFsa(root, options);

            if (options.HasFlag(ORegexOptions.ReversePattern))
            {
                nfa = _fsaOperator.ReverseFsa(nfa);
            }
            var dfa = _fsaOperator.MinimizeFsa(nfa);

            return(new FiniteAutomaton <TValue>(new CFSA <TValue>(dfa), new CFSA <TValue>(nfa)));
        }