Пример #1
0
 UnicodeCategoryTransition(RegExpState target, UnicodeCategoryTransition source)
     : base(target)
 {
     this._notMatch         = source._notMatch;
     this._fCategory        = source._fCategory;
     this._fCategoriesCodes = source._fCategoriesCodes;
 }
Пример #2
0
 RegExpDfa()
 {
     this._statesCache          = new Dictionary <RegExpDfaWave, RegExpDfaWave>();
     this._stringsToStatesCache = new RegExpStringKeyTable();
     this._initialState         = new RegExpState();
     this._finalState           = this._initialState;
 }
Пример #3
0
 public PlaceHoldersPredictAssociation(RegExpState state)
 {
     this._PlaceHolders       = new object[0];
     this._State              = state;
     this._PassedStatesSource = null;
     this._OptimisticHint     = string.Empty;
 }
Пример #4
0
        static RegExpDfa HardOr(RegExpDfa one, RegExpDfa merged)
        {
            RegExpDfa dfa = new RegExpDfa(one);
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in merged.GetAllStates())
            {
                RegExpState initialState;
                if (object.ReferenceEquals(merged._initialState, state))
                {
                    initialState = dfa._initialState;
                }
                else if (object.ReferenceEquals(merged._finalState, state))
                {
                    initialState = dfa._finalState;
                }
                else
                {
                    initialState = new RegExpState();
                }
                dictionary.Add(state, initialState);
            }
            foreach (RegExpState state3 in dictionary.Keys)
            {
                foreach (Transition transition in state3.Transitions)
                {
                    RegExpState state4 = dictionary[state3];
                    RegExpState target = dictionary[transition.Target];
                    state4.AddTransition(transition.Copy(target));
                }
            }
            return(dfa);
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="initialTransition"></param>
 public RegExpDfa(Transition initialTransition)
 {
     this._statesCache          = new Dictionary <RegExpDfaWave, RegExpDfaWave>();
     this._stringsToStatesCache = new RegExpStringKeyTable();
     this._initialState         = new RegExpState();
     this._initialState.AddTransition(initialTransition);
     this._finalState = initialTransition.Target;
 }
Пример #6
0
 static void CollectReachableStates(RegExpState nextState, IDictionary <RegExpState, bool> states)
 {
     if (!states.ContainsKey(nextState))
     {
         states.Add(nextState, true);
         foreach (Transition transition in nextState.Transitions)
         {
             CollectReachableStates(transition.Target, states);
         }
     }
 }
Пример #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="state"></param>
 public void AddStateWithEmptyTransitionsTargets(RegExpState state)
 {
     if (!this.Contains(state))
     {
         this.Add(state);
         foreach (Transition transition in state.Transitions)
         {
             if (transition.IsEmpty)
             {
                 this.AddStateWithEmptyTransitionsTargets(transition.Target);
             }
         }
     }
 }
Пример #8
0
        static RegExpDfa PowerOptional(RegExpDfa operand, int count)
        {
            if (count == 0)
            {
                return(null);
            }
            RegExpDfa head = new RegExpDfa(operand);

            if (head.CanReturnFromFinalState())
            {
                head = HardAnd(head, EmptyTransitionDfa);
            }
            if (head.CanReturnToInitialState())
            {
                head = HardAnd(EmptyTransitionDfa, head);
            }
            RegExpDfa dfa2 = new RegExpDfa(operand) | EmptyTransitionDfa;

            for (int i = 1; i < count; i++)
            {
                Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();
                foreach (RegExpState state in head.GetAllStates())
                {
                    RegExpState initialState;
                    if (object.ReferenceEquals(state, head._finalState))
                    {
                        initialState = dfa2._initialState;
                    }
                    else
                    {
                        initialState = new RegExpState();
                    }
                    dictionary.Add(state, initialState);
                }
                dfa2._initialState = dictionary[head._initialState];
                foreach (RegExpState state3 in dictionary.Keys)
                {
                    foreach (Transition transition in state3.Transitions)
                    {
                        RegExpState state4 = dictionary[state3];
                        RegExpState target = dictionary[transition.Target];
                        state4.AddTransition(transition.Copy(target));
                    }
                }
                dfa2._initialState.AddTransition(new EmptyTransition(dfa2._finalState));
            }
            return(dfa2);
        }
Пример #9
0
 public bool CanSkip(RegExpState suspectState, RegExpState finalState)
 {
     if (this.IsPassed(suspectState))
     {
         return(true);
     }
     if (suspectState != finalState)
     {
         foreach (Transition transition in this._State.Transitions)
         {
             if (((transition.Target != suspectState) && transition.IsEmpty) && (suspectState.CanReach(transition.Target) && !CanReachPast(suspectState, finalState, transition.Target, new Dictionary <RegExpState, bool>())))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #10
0
 public PlaceHoldersPredictAssociation(RegExpDfaWave.PlaceHoldersPredictAssociation prevHolder, Transition transition)
 {
     if (transition.IsEmpty)
     {
         this._PlaceHolders   = prevHolder._PlaceHolders;
         this._OptimisticHint = prevHolder._OptimisticHint;
     }
     else
     {
         this._PlaceHolders = new object[prevHolder._PlaceHolders.Length + 1];
         prevHolder._PlaceHolders.CopyTo(this._PlaceHolders, 0);
         if (transition.IsExact)
         {
             this._PlaceHolders[this._PlaceHolders.Length - 1] = transition.GetSampleChar();
         }
         this._OptimisticHint = prevHolder._OptimisticHint + transition.GetSampleChar();
     }
     this._State = transition.Target;
     this._PassedStatesSource = prevHolder;
 }
Пример #11
0
        RegExpDfa(RegExpDfa source)
        {
            this._statesCache          = new Dictionary <RegExpDfaWave, RegExpDfaWave>();
            this._stringsToStatesCache = new RegExpStringKeyTable();
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in source.GetAllStates())
            {
                dictionary.Add(state, new RegExpState());
            }
            this._initialState = dictionary[source._initialState];
            this._finalState   = dictionary[source._finalState];
            foreach (RegExpState state2 in dictionary.Keys)
            {
                foreach (Transition transition in state2.Transitions)
                {
                    Transition transition2 = transition.Copy(dictionary[transition.Target]);
                    dictionary[state2].AddTransition(transition2);
                }
            }
        }
Пример #12
0
        static RegExpDfa HardAnd(RegExpDfa head, RegExpDfa tail)
        {
            RegExpDfa dfa = new RegExpDfa(head);
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in tail.GetAllStates())
            {
                RegExpState state2 = object.ReferenceEquals(tail._initialState, state) ? dfa._finalState : new RegExpState();
                dictionary.Add(state, state2);
            }
            dfa._finalState = dictionary[tail._finalState];
            foreach (RegExpState state3 in dictionary.Keys)
            {
                foreach (Transition transition in state3.Transitions)
                {
                    RegExpState state4 = dictionary[state3];
                    RegExpState target = dictionary[transition.Target];
                    state4.AddTransition(transition.Copy(target));
                }
            }
            return(dfa);
        }
Пример #13
0
 static bool CanReachPast(RegExpState nextState, RegExpState targetState, RegExpState pastState, IDictionary <RegExpState, bool> states)
 {
     if (nextState == targetState)
     {
         return(true);
     }
     if (nextState != pastState)
     {
         if (states.ContainsKey(nextState))
         {
             return(false);
         }
         states.Add(nextState, true);
         foreach (Transition transition in nextState.Transitions)
         {
             if (CanReachPast(transition.Target, targetState, pastState, states))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Transition Copy(RegExpState target)
 {
     return(new AnySymbolTransition(target));
 }
Пример #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Transition Copy(RegExpState target)
 {
     return(new OneSymbolTransition(target, this._input));
 }
Пример #16
0
 WhiteSpaceTransition(RegExpState target, bool notMatch)
     : base(target)
 {
     this.notMatch = notMatch;
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Transition Copy(RegExpState target)
 {
     return(new UnicodeCategoryTransition(target, this));
 }
Пример #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Transition Copy(RegExpState target)
 {
     return(new WhiteSpaceTransition(target, this.notMatch));
 }
Пример #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public bool CanReach(RegExpState state)
 {
     return(this.ReachableStatesDictionary.ContainsKey(state));
 }
Пример #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="finalState"></param>
 public RegExpDfaWave(RegExpState finalState)
 {
     this._finalState = finalState;
 }
Пример #21
0
 void Add(RegExpState state)
 {
     this._states.Add(state, false);
 }
Пример #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Transition Copy(RegExpState target)
 {
     return(new WordTransition(target, this._notMatch));
 }
Пример #23
0
 bool IsPassed(RegExpState state)
 {
     return((this._State == state) || ((this._PassedStatesSource != null) && this._PassedStatesSource.IsPassed(state)));
 }
Пример #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 protected Transition(RegExpState target)
 {
     this._target = target;
 }
Пример #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public abstract Transition Copy(RegExpState target);
Пример #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Transition Copy(RegExpState target)
 {
     return(new EmptyTransition(target));
 }
Пример #27
0
 OneSymbolTransition(RegExpState target, char input)
     : base(target)
 {
     this._input = input;
 }
Пример #28
0
 WordTransition(RegExpState target, bool notMatch)
     : base(target)
 {
     this._notMatch = notMatch;
 }
Пример #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="target"></param>
 public EmptyTransition(RegExpState target)
     : base(target)
 {
 }
Пример #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public bool Contains(RegExpState state)
 {
     return(this._states.ContainsKey(state));
 }