コード例 #1
0
        __minor(instance continuous)
        {
            instance Gen::Stack <BacktrackRange> capt_ch = new Gen::Stack <BacktrackRange>();

            while (capt_ch.Count != this.max)
            {
                capt_ch.Push(new BacktrackRange(s));
                if (!node.Read(s))
                {
                    capt_ch.Pop().Restore(s);
                    break;
                }
            }

            while (capt_ch.Count >= this.min)
            {
                s.Success = true;
                return(null);

                if (capt_ch.Count == 0)
                {
                    break;
                }
                capt_ch.Pop().Restore(s);
            }

            s.Success = false;
            break return(null);
        }
コード例 #2
0
ファイル: Regex.cs プロジェクト: akinomyoga/afh
            /// <summary>
            /// 次に一致する部分を検索します。
            /// </summary>
            /// <returns>検索の結果一致する部分が見つかった場合に true を返します。
            /// それ以外の場合に false を返します。</returns>
            public bool Match()
            {
                do
                {
                    bool fInit = false;
                    if (first)
                    {
                        first = false;
                        fInit = true;
                    }
                    else
                    {
                        __debug__.RegexTestAssert(s.IsRoot);

                        if (OverlapSearch && st_indef.Count != 0)
                        {
                            // 次の可能性
                            st_indef.Pop().Restore(s);
                        }
                        else if (!FixStart && !s.Target.EndOfStream)
                        {
                            st_indef.Clear();

                            // 次の検索開始点
                            s.Pop();
                            s.ClearCaptures(0);
                            if (!OverlapSearch)
                            {
                                if (s.Index == index0)
                                {
                                    // 空一致の次
                                    s.Target.MoveNext();
                                }
                            }
                            else
                            {
                                s.Index = index0;
                                s.Target.MoveNext();
                            }

                            fInit = true;
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    if (fInit)
                    {
                        index0 = s.Target.Index;
                        s.Push(node.Nondeterministic?node.GetTester():new DeterministicTester(node));
                    }
                }while(!match_core());

                return(true);
            }
コード例 #3
0
        public ITester Read_Nondeterm(Status s)
        {
            switch (continuous_state)
            {
            default: throw new System.Exception("この関数の実行は終了しています。");

            case 0: break;

            case 1: goto R3;

            case 2: goto R4;
            }
#pragma warning disable 164
            capt_ch = new Gen::Stack <BacktrackRange>();
            L12 : if (!(capt_ch.Count != this.max))
            {
                goto L13;
            }
            s.Success = true;
            capt_ch.Push(new BacktrackRange(s));
            continuous_state = 1; return(node.GetTester());

            R3 :;

            if (!(!s.Success))
            {
                goto L16;
            }
            capt_ch.Pop().Restore(s);
            goto L13;
            L16 :;
            goto L12;
            L13 :;

            L14 : if (!(capt_ch.Count >= this.min))
            {
                goto L15;
            }
            s.Success        = true;
            continuous_state = 2; return(null);

            R4 :;

            if (capt_ch.Count == 0)
            {
                goto L15;
            }
            capt_ch.Pop().Restore(s);
            goto L14;
            L15 :;

            s.Success        = false;
            continuous_state = -1; return(null);

#pragma warning restore 164
        }
コード例 #4
0
        public ITester Read_Determ(Status s)
        {
            switch (continuous_state)
            {
            default: throw new System.Exception("この関数の実行は終了しています。");

            case 0: break;

            case 1: goto R5;
            }
#pragma warning disable 164
            capt_ch = new Gen::Stack <BacktrackRange>();
            L17 : if (!(capt_ch.Count != this.max))
            {
                goto L18;
            }
            capt_ch.Push(new BacktrackRange(s));
            if (!(!node.Read(s)))
            {
                goto L21;
            }
            capt_ch.Pop().Restore(s);
            goto L18;
            L21 :;
            goto L17;
            L18 :;

            L19 : if (!(capt_ch.Count >= this.min))
            {
                goto L20;
            }
            s.Success        = true;
            continuous_state = 1; return(null);

            R5 :;

            if (capt_ch.Count == 0)
            {
                goto L20;
            }
            capt_ch.Pop().Restore(s);
            goto L19;
            L20 :;

            s.Success        = false;
            continuous_state = -1; return(null);

#pragma warning restore 164
        }
コード例 #5
0
ファイル: Regex.cs プロジェクト: akinomyoga/afh
        /// <summary>
        /// 指定した Status を使用して matching を実行します。
        /// </summary>
        /// <param name="s">読み取りに使用する Status を指定します。
        /// ITester-Stack が空である事を想定しています。
        /// 中に何かある場合にはそれを別の所に待避して、new Stack を設定しておいて下さい。
        /// </param>
        /// <param name="node">要求するパターンを表現する構成体を指定します。</param>
        /// <returns>マッチングに成功した場合に true を返します。
        /// それ以外の場合に false を返します。</returns>
        internal bool match(Status s, INode node)
        {
            Gen::Stack <StatusInfo> st_indef = new Gen::Stack <StatusInfo>();

            s.Push(node.GetTester());
            while (true)
            {
                ITester test = s.Tester.Read(s);

                if (!s.Success)
                {
                    // a. Node 失敗
                    //-------------------
                    // 全体 失敗
                    if (s.IsRoot)
                    {
                        // * INDEFINICITY *
                        if (st_indef.Count == 0)
                        {
                            return(false);
                        }
                        st_indef.Pop().Restore(s);
                    }
                    else
                    {
                        s.Pop();
                    }
                }
                else if (test != null)
                {
                    // b. 入れ子 Node
                    //-------------------
                    s.Push(test);
                }
                else
                {
                    // c. 成功 (Node 終了)
                    //-------------------
                    // 全体 成功
                    if (s.IsRoot)
                    {
                        return(true);
                    }

                    if (s.Tester.Indefinite)
                    {
                        // * INDEFINICITY *
                        st_indef.Push(new StatusInfo(s));
                    }

                    s.Pop();
                }
            }
        }
コード例 #6
0
ファイル: Selector.cs プロジェクト: akinomyoga/afh
        public System.Collections.IEnumerable Enumerate(HTMLElement parent, Gen::Stack <string> stack)
        {
            System.Collections.IEnumerable @enum = this.getBaseEnum(parent);
            if (@enum == null)
            {
                yield break;
            }
            int  i;
            bool first = this.relation == '+' || this.relation == '-';
            int  stcC  = stack.Count;

            foreach (HTMLElement elem in @enum)
            {
                for (i = 0; i < this.len; i++)
                {
                    if (!this.testers[i].Test(elem, stack))
                    {
                        break;
                    }
                }
                if (i == this.len)
                {
                    yield return(elem);

                    while (stack.Count > stcC)
                    {
                        stack.Pop();
                    }
                    if (first)
                    {
                        break;
                    }
                }
            }
            // 元の状態に戻してから終わる (MoveNext = false)
            while (stack.Count > stcC)
            {
                stack.Pop();
            }
        }
コード例 #7
0
ファイル: CppScanner.cs プロジェクト: akinomyoga/afh
 private string PopBuffer()
 {
     return(buf_stack.Pop().ToString());
 }
コード例 #8
0
ファイル: CppScanner.cs プロジェクト: akinomyoga/afh
 /// <summary>
 /// 挿入したソースコードから抜け出すと共に、
 /// 次の単語の読み取りを行います。
 /// </summary>
 /// <returns></returns>
 private bool PopStateAndNext()
 {
     st_state.Pop().Restore(this);
     return(this.ReadNext());
 }