示例#1
0
 /// <summary>
 /// 根据当前的正则表达式构造 NFA。
 /// </summary>
 /// <param name="nfa">要构造的 NFA。</param>
 internal override void BuildNfa(Nfa nfa)
 {
     innerExp.BuildNfa(nfa);
     if (TrailingExpression != null)
     {
         NfaState head = nfa.HeadState;
         TrailingHeadState = nfa.TailState;
         TrailingExpression.BuildNfa(nfa);
         TrailingHeadState.Add(nfa.HeadState);
         nfa.HeadState = head;
         TrailingHeadState.StateType = NfaStateType.TrailingHead;
         nfa.TailState.StateType     = NfaStateType.Trailing;
     }
 }
示例#2
0
        /// <summary>
        /// 返回当前对象的字符串表示形式。
        /// </summary>
        /// <returns>当前对象的字符串表示形式。</returns>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            if (BeginningOfLine)
            {
                builder.Append('^');
            }
            builder.Append(innerExp.ToString());
            if (TrailingExpression != null)
            {
                if (TrailingExpression == EndOfLine)
                {
                    builder.Append('$');
                }
                else
                {
                    builder.Append('/');
                    builder.Append(TrailingExpression.ToString());
                }
            }
            return(builder.ToString());
        }