/// <summary> /// 返回表示行的起始位置的正则表达式。 /// </summary> /// <param name="innerExp">内部的正则表达式。</param> /// <returns>表示行的起始位置的正则表达式。</returns> /// <overloads> /// <summary> /// 返回表示行的起始位置的正则表达式。 /// </summary> /// </overloads> public static Regex BeginningOfLine(Regex innerExp) { AnchorExp anchorExp = innerExp as AnchorExp; if (anchorExp == null) { anchorExp = new AnchorExp(innerExp); } anchorExp.BeginningOfLine = true; return(anchorExp); }
/// <summary> /// 返回表示向前看的正则表达式。 /// </summary> /// <param name="innerExp">内部的正则表达式。</param> /// <param name="regex">要向前看的正则表达式。</param> /// <returns>表示向前看的正则表达式。</returns> /// <overloads> /// <summary> /// 返回表示向前看的正则表达式。 /// </summary> /// </overloads> public static Regex Trailing(Regex innerExp, Regex regex) { AnchorExp anchorExp = innerExp as AnchorExp; if (anchorExp == null) { anchorExp = new AnchorExp(innerExp); } anchorExp.TrailingExpression = regex; return(anchorExp); }
/// <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"); } }
/// <summary> /// 返回表示向前看的正则表达式。 /// </summary> /// <param name="innerExp">内部的正则表达式。</param> /// <param name="regex">要向前看的正则表达式。</param> /// <returns>表示向前看的正则表达式。</returns> /// <overloads> /// <summary> /// 返回表示向前看的正则表达式。 /// </summary> /// </overloads> public static Regex Trailing(Regex innerExp, Regex regex) { AnchorExp anchorExp = innerExp as AnchorExp; if (anchorExp == null) { anchorExp = new AnchorExp(innerExp); } anchorExp.TrailingExpression = regex; return anchorExp; }
/// <summary> /// 返回表示行的起始位置的正则表达式。 /// </summary> /// <param name="innerExp">内部的正则表达式。</param> /// <returns>表示行的起始位置的正则表达式。</returns> /// <overloads> /// <summary> /// 返回表示行的起始位置的正则表达式。 /// </summary> /// </overloads> public static Regex BeginningOfLine(Regex innerExp) { AnchorExp anchorExp = innerExp as AnchorExp; if (anchorExp == null) { anchorExp = new AnchorExp(innerExp); } anchorExp.BeginningOfLine = true; return anchorExp; }