示例#1
0
        /// <summary>
        /// 检查正则表达式是否可以被嵌套。
        /// </summary>
        /// <param name="regex">要检查的正则表达式。</param>
        protected static void CheckRegex(Regex regex)
        {
            AnchorExp anchor = regex as AnchorExp;

            if (anchor != null)
            {
                if (anchor.BeginningOfLine)
                {
                    throw CompilerCommonExceptions.NestedBeginningOfLine("regex");
                }
                if (anchor.TrailingExpression == AnchorExp.EndOfLine)
                {
                    throw CompilerCommonExceptions.NestedEndOfLine("regex");
                }
                throw CompilerCommonExceptions.NestedTrailing("regex");
            }
            if (regex is EndOfFileExp)
            {
                throw CompilerCommonExceptions.NestedEndOfFile("regex");
            }
        }