Exemple #1
0
        public MatingContext DepthIncrement()
        {
            var mc = new MatingContext();

            mc.NamedRegexes   = NamedRegexes;
            mc.Captures       = Captures;
            mc.ReferenceDepth = ReferenceDepth + 1;
            return(mc);
        }
Exemple #2
0
 /// <summary>
 /// テキスト全体でマッチ箇所を全て列挙
 /// </summary>
 /// <param name="str"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public IEnumerable <RegexMatch> Matches(StringPointer str, MatingContext context)
 {
     for (int i = 0; i < str.Length + 1; i++)
     {
         var subStr = str.SubString(i);
         foreach (var match in HeadMatches(subStr, new MatingContext()))
         {
             yield return(match);
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// 文字列の先頭から、後続を考慮したマッチを優先度順に列挙
 /// </summary>
 /// <param name="str"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public IEnumerable <RegexMatch> HeadMatches(StringPointer str, MatingContext context)
 {
     if (_nextRegex == null)//末端は自身のマッチを返せばいい。
     {
         foreach (var matching in SimpleMatchings(str, context))
         {
             yield return(matching);
         }
     }
     else//末端以外は、自分以降にマッチが存在するマッチを返す。
     {
         foreach (var selfMatch in SimpleMatchings(str, context))
         {
             var nextStr = str.SubString(selfMatch.Length);
             foreach (var nextMatch in _nextRegex.HeadMatches(nextStr, context))
             {
                 yield return(new ArrayMatch(str, selfMatch, nextMatch));
             }
         }
     }
 }
Exemple #4
0
 public sealed override IEnumerable <RegexMatch> SimpleMatchings(StringPointer str, MatingContext context)
 {
     foreach (var match in Content.HeadMatches(str, context))
     {
         yield return(new CompositeMatch(this, str, match));
     }
 }
Exemple #5
0
 /// <summary>
 /// 与えられた文字列が先頭からこの正規表現にマッチするか判定。後続のことは考慮しない。
 /// </summary>
 /// <param name="str"></param>
 /// <param name="context"></param>
 /// <returns>マッチ優先度高い順のマッチ。マッチしないときは空のIEnumerable</returns>
 public abstract IEnumerable <RegexMatch> SimpleMatchings(StringPointer str, MatingContext context);
Exemple #6
0
 /// <summary>
 /// 文字列の末尾で終わる、後続を考慮したマッチを優先度順に列挙
 /// (後よみ用?)
 /// </summary>
 /// <param name="str"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public IEnumerable <RegexMatch> TailMatches(StringPointer str, MatingContext context)
 {
     return(Matches(str, context).Where(match => match.AfterStr == ""));
 }
Exemple #7
0
 /// <summary>
 /// このRegexChainの再優先マッチを取得。マッチしなければnull
 /// </summary>
 /// <param name="str"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public RegexMatch HeadMatch(StringPointer str, MatingContext context)
 {
     return(HeadMatches(str, context).FirstOrDefault());
 }
Exemple #8
0
 protected IEnumerable <RegexMatch> PerfectMatches(StringPointer str, MatingContext context)
 {
     return(HeadMatches(str, context).Where(m => m.Length == str.Length));
 }