Exemplo n.º 1
0
        /// <summary>
        /// 指定した define 定義が __afh:: 型であるかどうかを判定し、
        /// __afh:: 型であると判断された場合には、そのハンドラを作成して返します。
        /// </summary>
        /// <param name="content"></param>
        /// <param name="proc"></param>
        /// <returns>__afh:: 型であると判定された場合に true を返します。</returns>
        public static bool TryCreateInstance(string content, out IDefineProcessor proc)
        {
            do
            {
                Rgx::Match m = rx_afhdefine.Match(content);
                if (!m.Success)
                {
                    break;
                }

                string name = m.Groups["name"].Value;
                if (!methods.ContainsKey(name))
                {
                    break;
                }

                Rgx::CaptureCollection cc = m.Groups["arg"].Captures;
                string[] args             = new string[cc.Count];
                for (int i = 0; i < cc.Count; i++)
                {
                    args[i] = cc[i].Value.Trim();
                }

                proc = new AfhDefineProcessor(name, args);
                return(true);

#pragma warning disable 162
            }while(false);
#pragma warning restore 162

            // 失敗した場合
            proc = null;
            return(false);
        }
Exemplo n.º 2
0
            public Define(Rgx::Match m)
            {
                this.name = m.Groups["name"].Value;
                string content = m.Groups["content"].Value.Trim();

                int c_param = 0;

                foreach (Rgx::Capture param in m.Groups["param"].Captures)
                {
                    content = Rgx::Regex.Replace(content, @"\b" + param.Value + @"\b", PARAM_HEAD + c_param++.ToString());
                }
                //this.content=content;

                string rp = @"\b" + this.name + @"\b";

                if (c_param == 1)
                {
                    rp += DEFINE_ARGS1;
                }
                else if (c_param > 0)
                {
                    rp += string.Format(DEFINE_ARGS2, c_param - 1);
                }
                this.rp_entity = rp;

                this.start = m.Index + m.Length;

                //-- 適当なハンドラを初期化
                if (AfhDefineProcessor.TryCreateInstance(content, out this.proc))
                {
                    return;
                }
                this.proc = new DefineProcessor(content);
            }