using system;
using system.text;
using system.text.regularexpressions;
namespace com.osleague.component
{
/// <summary>
/// 語法分析器,將所有code根據語法進行變色
/// <list type="vb">支持vb.net</list>
/// <list type="cs">支持cs</list>
/// <author>掉掉</author>
/// <date>2002年5月14日</date>
/// <memo>
/// 練習正則表達式
/// </memo>
/// </summary>
public class codeanalysis
{
//
//定義html開始和結束的語句,用于語法變色
//
const string tag_fntred = @"<font color=""red"">";
const string tag_fntblue = @"<font color=""blue"">" ;
const string tag_fntgrn = @"<font color=""green"">" ;
const string tag_fntmrn = @"<font color=""maroon"">" ;
const string tag_fntblack = @"<font color=""black"">" ;
const string tag_efont = @"</font>" ;
const string tag_spnyellow = @"<span background-color: yellow;"">";
const string tag_espan = @"</span>";
const string tag_b = @"<b>";
const string tag_eb = @"</b>";
const string tag_comment = @"<font colr=#008200>";
const string tag_ecomment = @"</font>";
//
public codeanalysis()
{
//
// todo: 在此處添加構造函數邏輯
//
}
/// <summary>
/// 處理vb.net代碼,彩色化..
/// </summary>
/// <param name="code">傳入的code</param>
/// <returns>處理過后的代碼</returns>
public string parsevb(string code)
{
//
//定義vb.net中關鍵字,將其存為數組
//
string[] vb_keyword = new string[]
{
"addhandler","addressof","andalso","alias","and","ansi","as","assembly","auto","boolean",
"byref","byte","byval","call","case","catch","cbool","cbyte","cchar",
"cdate","cdec","cdbl","char","cint","class","clng","cobj","const",
"cshort","csng","cstr","ctype","date","decimal","declare","default",
"delegate","dim","directcast","do","double","each","else","elseif","end",
"enum","erase","error","event","exit","false",
"finally","for","friend","function","get","gettype","goto","handles","if",
"implements","imports","in","inherits","integer","interface",
"is","let","lib","like","long","loop","me","mod","module",
"mustinherit","mustoverride","mybase","myclass","namespace","new","next","not","nothing",
"notinheritable","notoverridable","object","on","option","optional","or","orelse",
"overloads","overridable","overrides","paramarray","preserve","private","property","protected","public",
"raiseevent","readonly","redim","removehandler","resume","return",
"select","set","shadows","shared","short","single","static","step","stop",
"string","structure","sub","synclock","then","throw",
"to","true","try","typeof","unicode","until","variant","when","while",
"with","withevents","writeonly","xor"
};
//
//設定轉換代碼顏色
//
string replacevbcomment = tag_comment + "$1" + tag_ecomment;
string replacevbkeyword = tag_fntblue + "${char}" + tag_efont;
//開始轉換
for (int i=0;i<vb_keyword.length;i++)
{
string tempdirectives = @"(?<char>(/s" + vb_keyword[i] + "|" + vb_keyword[i] + @"/s))";
code = regex.replace(code,tempdirectives,replacevbkeyword,regexoptions.ignorecase);
code = regex.replace(code,@"'(?<x>[^/r/n]*)",replacevbcomment);
code = regex.replace(code,@"rem (?<x>[^/r/n]*)",replacevbcomment);
}
return code;
}
}<
國內最大的酷站演示中心!