UnicodeCategoryTransition(RegExpState target, UnicodeCategoryTransition source) : base(target) { this._notMatch = source._notMatch; this._fCategory = source._fCategory; this._fCategoriesCodes = source._fCategoriesCodes; }
RegExpDfa() { this._statesCache = new Dictionary <RegExpDfaWave, RegExpDfaWave>(); this._stringsToStatesCache = new RegExpStringKeyTable(); this._initialState = new RegExpState(); this._finalState = this._initialState; }
public PlaceHoldersPredictAssociation(RegExpState state) { this._PlaceHolders = new object[0]; this._State = state; this._PassedStatesSource = null; this._OptimisticHint = string.Empty; }
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); }
/// <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; }
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); } } }
/// <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); } } } }
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); }
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); }
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; }
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); } } }
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); }
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); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public override Transition Copy(RegExpState target) { return(new AnySymbolTransition(target)); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public override Transition Copy(RegExpState target) { return(new OneSymbolTransition(target, this._input)); }
WhiteSpaceTransition(RegExpState target, bool notMatch) : base(target) { this.notMatch = notMatch; }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public override Transition Copy(RegExpState target) { return(new UnicodeCategoryTransition(target, this)); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public override Transition Copy(RegExpState target) { return(new WhiteSpaceTransition(target, this.notMatch)); }
/// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> public bool CanReach(RegExpState state) { return(this.ReachableStatesDictionary.ContainsKey(state)); }
/// <summary> /// /// </summary> /// <param name="finalState"></param> public RegExpDfaWave(RegExpState finalState) { this._finalState = finalState; }
void Add(RegExpState state) { this._states.Add(state, false); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public override Transition Copy(RegExpState target) { return(new WordTransition(target, this._notMatch)); }
bool IsPassed(RegExpState state) { return((this._State == state) || ((this._PassedStatesSource != null) && this._PassedStatesSource.IsPassed(state))); }
/// <summary> /// /// </summary> /// <param name="target"></param> protected Transition(RegExpState target) { this._target = target; }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public abstract Transition Copy(RegExpState target);
/// <summary> /// /// </summary> /// <param name="target"></param> /// <returns></returns> public override Transition Copy(RegExpState target) { return(new EmptyTransition(target)); }
OneSymbolTransition(RegExpState target, char input) : base(target) { this._input = input; }
WordTransition(RegExpState target, bool notMatch) : base(target) { this._notMatch = notMatch; }
/// <summary> /// /// </summary> /// <param name="target"></param> public EmptyTransition(RegExpState target) : base(target) { }
/// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> public bool Contains(RegExpState state) { return(this._states.ContainsKey(state)); }