/// <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); }
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); }
static string GetCommandInitializer_1308(Rgx::Match m){ // コマンドの種類 string cmdtype=m.Groups["cmdtype"].Value; string argdef=RegExp.UnquoteText(m.Groups["arg"].Value); string commandTypeAndParam; if(argdef!="") commandTypeAndParam=RegExp.SingleQuoteText(cmdtype+";"+argdef); else commandTypeAndParam=RegExp.SingleQuoteText(cmdtype); // コマンドの内容 string definition=m.Groups["str"].Value; if(definition!=""){ // @ 文字列を通常文字列に変換 if(definition[0]=='@'){ string q=definition[1].ToString(); definition=q+definition.Substring(2).Replace("\\","\\\\").Replace(q+q,"\\"+q); } }else{ definition=m.Groups["func"].Value; if(cmdtype=="f@") definition="function(doc,cmdName){"+definition+"}"; else definition="function(doc,argv){"+definition+"}"; } return "["+commandTypeAndParam+","+definition+"]"; }
static string GetCommandInitializer(Rgx::Match m){ // コマンドの種類 string cmdtype='"'+m.Groups["cmdtype"].Value+'"'; // 既定の引数 string argdef=m.Groups["arg"].Value; if(argdef=="") argdef="null"; else if(argdef[0]!='"'&&argdef[0]!='\'') argdef=RegExp.DoubleQuoteText(argdef); // コマンドの内容 string definition=m.Groups["str"].Value; { if(definition!=""){ // @ 文字列を通常文字列に変換 if(definition[0]=='@'){ string q=definition[1].ToString(); definition=q+definition.Substring(2).Replace("\\","\\\\").Replace(q+q,"\\"+q); } }else{ definition=m.Groups["func"].Value; if(cmdtype=="\"f@\"") definition="function(doc,cmdName){"+definition+"}"; else definition="function(doc,argv){"+definition+"}"; } } return "new ns.Command2("+cmdtype+","+argdef+","+definition+")"; }
public static void Test(Argument args) { test_args = args; args.WriteLine("------------------------------------"); args.WriteLine(" gzjs -- Transform Test"); args.WriteLine("------------------------------------"); Rgx::Match m = Rgx::Regex.Match(@"(i<144)", @"\b\d+\b|\b[\w\d]{2,}\b"); if (m.Success) { args.WriteLine("OK: {0}", m.Value); } else { args.WriteLine("NG: reg_gzjs_directive"); } Assert(Rgx::Regex.Match(@"else return", @"\b +\b").Value, " "); Assert(Rgx::Regex.Match(@"else return", @"\b +\B").Value, " "); Assert(Rgx::Regex.Match(@"else return", @"\B +\b").Value, " "); Assert(Rgx::Regex.Match(@"else return", @"\B +\B").Value, " "); { Rgx::Regex reg = new Rgx::Regex("^" + _.rex_braces + "$", Rgx::RegexOptions.Multiline); Assert(reg.Match(@" work(); ").Success, true); Assert(reg.Match(@" {work({a:b});} var c={0:1} ").Success, true); Assert(reg.Match(@" {work(a:b});} var c={} ").Success, false); } { Rgx::Regex reg = new Rgx::Regex(@"^\{" + _.rex_braces + @"\}$", Rgx::RegexOptions.Multiline); Assert(reg.Match(@"{ {work({a:b});} var c={0:1} }").Success, true); Assert(reg.Match(@"{ {work(a:b});} var c={} }").Success, false); } }
private string Evaluator(Rgx::Match m) { string r = this.content; for (int i = 0; i < this.args.Length; i++) { r = Rgx::Regex.Replace(r, @"\b" + this.args[i] + @"\b", m.Groups[this.args[i]].Value); } return(r); }
public string GetProcessedAfter(Rgx::Match match) { string ret = this.after; ret = reg_after.Replace(ret, delegate(Rgx::Match m){ //System.Console.WriteLine("replacement match: "+m.Value); if (m.Groups["num"].Success) { int n = int.Parse(m.Groups["num"].Value); if (n == 0) { return(match.Value); } Rgx::Group g = match.Groups[n]; if (g != null && g.Success) { return(g.Value); } } else if (m.Groups["name"].Success) { Rgx::Group g = match.Groups[m.Groups["name"].Value]; if (g != null && g.Success) { return(g.Value); } } else { switch (m.Groups["cmd"].Value) { case "include": string fname = m.Groups["arg"].Value.Trim(); fname = System.IO.Path.Combine(this.directory, fname); if (!System.IO.File.Exists(fname)) { break; } return(System.IO.File.ReadAllText(fname)); } } return(m.Value); }); return(ret); }
static string GetEnvironmentInitializer(Rgx::Match m){ // コマンドの種類 string cmdtype,context; { string value=m.Groups["cmdtype"].Value; int index=value.IndexOf(':'); if(index>=0){ cmdtype=RegExp.DoubleQuoteText(value.Substring(0,index)); context=RegExp.DoubleQuoteText(value.Substring(index+1)); }else{ cmdtype=RegExp.DoubleQuoteText(value); context="_CtxName"; // 登録先の context } } // 既定の引数 string argdef=m.Groups["arg"].Value; if(argdef=="") argdef="null"; else if(argdef[0]!='"'&&argdef[0]!='\'') argdef=RegExp.DoubleQuoteText(argdef); // コマンドの内容 string definition=m.Groups["str"].Value; { if(definition!=""){ // @ 文字列を通常文字列に変換 if(definition[0]=='@'){ string q=definition[1].ToString(); definition=q+definition.Substring(2).Replace("\\","\\\\").Replace(q+q,"\\"+q); } }else{ definition=m.Groups["func"].Value; definition="function(doc,argv){"+definition+"}"; } } return "ns.Environment.Create("+cmdtype+","+argdef+","+definition+","+context+")"; }
public static void Resolve(ref string text, ReportError report) { Rgx::MatchCollection mc = rx_delete_s.Matches(text); for (int i = mc.Count - 1; i >= 0; i--) { Rgx::Match m_s = mc[i]; Rgx::Match m_e = rx_delete_e.Match(text, m_s.Index); if (!m_e.Success) { report("//#>>delete に対応する //#<<delete が存在しません。", m_s.Index); continue; } // 削除 int ss = m_s.Index; //int se=ss+m_s.Length; int es = m_e.Index; int ee = es + m_e.Length; text = text.Substring(0, ss) + text.Substring(ee); } }
/// <summary> /// 指定した "//#→template" の解決を行います。 /// </summary> /// <param name="text">処理する対象の文字列を指定します。</param> /// <param name="m_s">rx_template_s "//#→template" の一致を指定します。</param> /// <param name="report">エラー報告先を指定します。</param> /// <returns>成功した場合に true を返します。失敗した場合に false を返します。</returns> private static bool ResolveTemplate(ref string text, Rgx::Match m_s, ReportError report) { const string TEMP_LOC = "__AFH_TEMPLATE_LOC__"; Rgx::Match m_e = rx_template_e.Match(text, m_s.Index); if (!m_e.Success) { report("//#→template に対応する //#←template が存在しません。", m_s.Index); return(false); } int ss = m_s.Index; int se = ss + m_s.Length; int es = m_e.Index; int ee = es + m_e.Length; string t_name = m_s.Groups["name"].Value; Template temp = new Template(t_name, m_s.Groups["param"].Captures, text.Substring(se, es - se)); text = text.Substring(0, ss) + TEMP_LOC + text.Substring(ee); // // #t_name<param> の変換 // temp.ApplyToDeclEntity(ref text, ss); // // /*#t_name<param>*/ の変換 (template 関数に利用) // string insts = temp.ApplyToInlineEntity(ref text, ss); // // /*#t_name<param>*/ の実体化関数を配置 // text = text.Replace(TEMP_LOC, insts); return(true); }
public static string UnDecorateName(string name) { if (name.Length == 0) { return(""); } if (name[0] == '$') { if (name.StartsWith("$ArrayType$")) { // case: 配列型 name = "?a@@3" + name.Substring(11) + "?"; name = UnDecorateSymbolName(name).Replace("()", ""); return("<" + name + ">"); } else if (name.StartsWith("$PTMType$")) { // case: メンバへのポインタ (Pointer To Member) name = "?a@@3" + name.Substring(9) + "?"; name = UnDecorateSymbolName(name); return("<" + name + ">"); } } else if (name[0] == '?') { // case: ??__E / ??__F の接頭辞 ←何を意味するのか? if (name.StartsWith("??__")) { if (name.Length >= 12 && (name[4] == 'E' || name[4] == 'F') && name.EndsWith("@@YMXXZ")) { string specialName = ""; if (name[4] == 'E') { specialName = "static member constructor"; // ←憶測 } else if (name[4] == 'F') { specialName = "static member destructor"; // ←憶測 } name = UnDecorateName(name.Substring(5, name.Length - 12)); return("void __clrcall `" + specialName + "'<" + name + ">(void)"); } } // case: ?A0xXXXXXXXX. の接頭辞 Rgx::Match m = Rgx::Regex.Match(name, @"\?A(0x[a-fA-F0-9]{8})\."); if (m.Success) { name = "[" + m.Groups[1].Value + "]" + UnDecorateName(name.Substring(13)); return(name); } // case: その他 name = Rgx::Regex.Replace(name.Replace("$$Q", ""), @"\<\b(\w+)\b\>", "_langle_$1_rangle_"); name = UnDecorateSymbolName(name); name = Rgx::Regex.Replace(name, @"_langle_(\w+)_rangle_", "<$1>"); return(name); } return(name); }