国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

VB.NET的語法解析程序

2024-07-10 13:02:36
字體:
來源:轉載
供稿:網友
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 style=""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;    
        }
    }
}
國內最大的酷站演示中心!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永城市| 鄂托克前旗| 方山县| 辽阳县| 乌拉特前旗| 克什克腾旗| 莎车县| 若尔盖县| 桐梓县| 会东县| 涟水县| 菏泽市| 开鲁县| 扶绥县| 綦江县| 独山县| 岳池县| 壶关县| 北辰区| 山阳县| 广南县| 祁东县| 雷波县| 准格尔旗| 玉环县| 华池县| 禹城市| 屯昌县| 高阳县| 南陵县| 宁明县| 鹤庆县| 大新县| 鱼台县| 海南省| 昌黎县| 峨眉山市| 澎湖县| 西昌市| 济阳县| 南充市|