/// <summary> /// Constructor. /// </summary> /// <param name="owner">Generator that generated the sentence.</param> /// <param name="tokens">Tokens.</param> public Sentence(CaptureCodeGeneratorBase owner, params object[] tokens) { _owner = owner; _tokens = tokens; if (_tokens == null) { _tokens = new object[0]; } }
/// <summary> /// 重複した関数であるか。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="sentence">センテンス。</param> /// <param name="function">関数。</param> /// <returns>重複した関数であるか。</returns> private static bool IsDuplicationFunction(CaptureCodeGeneratorBase generator, Sentence sentence, string function) { if (!ReferenceEquals(generator, sentence.Owner)) { return(false); } if (sentence.Tokens.Length <= 2) { return(false); } if (!(sentence.Tokens[0] is TokenName) || (sentence.Tokens[1] == null)) { return(false); } return(sentence.Tokens[1].ToString().IndexOf("." + function) == 0); }
/// <summary> /// 重複した関数の削除。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="list">リスト。</param> /// <param name="function">関数。</param> internal static void RemoveDuplicationFunction(CaptureCodeGeneratorBase generator, List <Sentence> list, string function) { bool findChangeText = false; for (int i = list.Count - 1; 0 <= i; i--) { if (IsDuplicationFunction(generator, list[i], function)) { if (findChangeText) { list.RemoveAt(i); } findChangeText = true; } else { findChangeText = false; } } }
/// <summary> /// 重複したセンテンスの削除。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="list">リスト。</param> /// <param name="pattern">パターン。</param> internal static void RemoveDuplicationSentence(CaptureCodeGeneratorBase generator, List <Sentence> list, object[] pattern) { Sentence old = null; for (int i = list.Count - 1; 0 <= i; i--) { Sentence current = list[i]; if (ReferenceEquals(generator, current.Owner)) { if (old != null) { if (IsDuplicationSentence(old, current, pattern)) { list.RemoveAt(i); } } } old = current; } }