/// <summary> /// 递归获取指定转换开始能达到的所有状态的集合。 /// </summary> /// <param name="transition">指定的转换。</param> /// <returns>指定转换开始能达到的所有状态的集合。</returns> /// <exception cref="ArgumentNullException"><paramref name="transition"/> 的值为 null 。</exception> public static IEnumerable <IRegexFSMState <T> > RecurGetStates <T>(this IRegexFSMTransition <T> transition) { if (transition == null) { throw new ArgumentNullException(nameof(transition)); } return(transition.Target.RecurGetStates()); }
private static void RecurGetReachableTransitionsInternal <T>(IRegexFSMTransition <T> transition, HashSet <IRegexFSMTransition <T> > transitions) { foreach (var t in transition.Target.Transitions) { if (transitions.Add(t) && t is IEpsilonTransition) { RegexFSMUtility.RecurGetReachableTransitionsInternal(transition, transitions); } } }
/// <summary> /// 递归获取指定转换开始能经到的所有转换的集合。 /// </summary> /// <param name="transition">指定的转换。</param> /// <returns>指定转换开始能经到的所有转换的集合。</returns> /// <exception cref="ArgumentNullException"><paramref name="transition"/> 的值为 null 。</exception> public static IEnumerable <IRegexFSMTransition <T> > RecurGetTransitions <T>(this IRegexFSMTransition <T> transition) { if (transition == null) { throw new ArgumentNullException(nameof(transition)); } HashSet <IRegexFSMTransition <T> > transitions = new HashSet <IRegexFSMTransition <T> >(); RegexFSMUtility.RecurGetTransitionsInternal(transition, transitions); return(transitions); }
private static void RecurGetTransitionsInternal <T>(IRegexFSMTransition <T> transition, HashSet <IRegexFSMTransition <T> > transitions) { if (transitions.Add(transition)) { if (transition.Target != null) { foreach (var _transition in transition.Target.Transitions.Where(t => t != null)) { RegexFSMUtility.RecurGetTransitionsInternal(_transition, transitions); } } } }
/// <summary> /// 递归获取指定转换开始无须接受输入就能达到的所有状态的集合。 /// </summary> /// <param name="transition">指定的转换。</param> /// <returns>指定转换开始无须接受输入就能达到的所有状态的集合。</returns> public static IEnumerable <IRegexFSMState <T> > RecurGetReachableStates <T>(this IRegexFSMTransition <T> transition) { if (transition == null) { throw new ArgumentNullException(nameof(transition)); } HashSet <IRegexFSMState <T> > states = new HashSet <IRegexFSMState <T> > { transition.Target }; RegexFSMUtility.RecurGetReachableStatesInternal(transition.Target, states); return(states); }
public IRegexFSM <T> GenerateRegexFSMFromRegexObject(RegexObject <T> regex, RegexOptions options) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } IRegexNFA <T> nfa = this.contextInfo.ActivateRegexNFA(); IRegexNFAState <T> startState = this.contextInfo.ActivateRegexNFAState(); nfa.StartState = startState; IRegexFSMTransition <T> transition = this.GenerateNFATransitionFromRegexObject(regex, nfa, startState); IRegexNFAState <T> endState = this.contextInfo.ActivateRegexNFAState(true); nfa.SetTarget(transition, endState); return(nfa); }
/// <summary> /// 从 <see cref="RegexDFA{T}"/> 的一个指定状态移除指定转换。 /// </summary> /// <param name="state">指定的状态。</param> /// <param name="transition">要添加的转换。</param> /// <returns>一个值,指示操作是否成功。</returns> public override bool RemoveTransition(IRegexFSMState <T> state, IRegexFSMTransition <T> transition) => this.RemoveTransition(state, transition);
/// <summary> /// 为 <see cref="RegexDFA{T}"/> 的一个指定状态添加指定转换。 /// </summary> /// <param name="state">指定的状态。</param> /// <param name="transition">要添加的转换。</param> /// <returns>一个值,指示操作是否成功。</returns> public sealed override bool AttachTransition(IRegexFSMState <T> state, IRegexFSMTransition <T> transition) => this.AttachTransition((IRegexDFAState <T>)state, (IAcceptInputTransition <T>)transition);
/// <summary> /// 从 <see cref="RegexNFA{T}"/> 的一个指定状态移除指定转换。 /// </summary> /// <param name="state">指定的状态。</param> /// <param name="transition">要添加的转换。</param> /// <returns>一个值,指示操作是否成功。</returns> public sealed override bool RemoveTransition(IRegexFSMState <T> state, IRegexFSMTransition <T> transition) => base.RemoveTransition(state, transition);
/// <summary> /// 为 <see cref="RegexNFA{T}"/> 的一个指定状态添加指定转换。 /// </summary> /// <param name="state">指定的状态。</param> /// <param name="transition">要添加的转换。</param> /// <returns>一个值,指示操作是否成功。</returns> public sealed override bool AttachTransition(IRegexFSMState <T> state, IRegexFSMTransition <T> transition) => base.AttachTransition(state, transition);
/// <summary> /// 移除指定的转换。 /// </summary> /// <param name="transition">要添加的转换。</param> /// <returns>一个值,指示操作是否成功。</returns> /// <exception cref="ArgumentNullException"><paramref name="transition"/> 的值为 null 。</exception> public virtual bool RemoveTransition(IRegexFSMTransition <T> transition) => base.RemoveTransition(transition);
/// <summary> /// 添加指定的转换。 /// </summary> /// <param name="transition">要添加的转换。</param> /// <returns>一个值,指示操作是否成功。</returns> /// <exception cref="ArgumentNullException"><paramref name="transition"/> 的值为 null 。</exception> public virtual bool AttachTransition(IRegexFSMTransition <T> transition) => base.AttachTransition(transition);