• 注册
  • 关于作者
    企业认证:趣记站长
    关注 6 粉丝 4 喜欢 9 内容 992
    江西省·南昌市
    聊天 送礼
    • 查看作者
    • 完整的VB.NET的语法解析程序

      作者: blood

        比较长,不过支持全部的关键字,直接就可以用了。

      using System;

      using System.Text;

      using System.Text.RegularExpressions;

      namespace Com.OSLeague.Component

      {

      /// <summary>

      /// 语法分析器,

      在Visual Basic .NET中文件I/O选项
      VB.Net调用存储过程并得到返回值,详解VB.NET对象浏览器作用体现,老生常谈:从VB6迁移到VB.net,VB.net2008精彩实例,窗体应用技巧,用VB.net2008打造你的影音播放器,一个Office 2003风格的通知控件(VB.NET),在VB.NET中操作MySQL数据库,vb.net开发中使用excel插件的代码,vb.net封装组件成com的方法,.NET环境下几种不同的邮件发送解决方案,用.net动态创建类的实例,VB.NET实现DataList横向数据交替变色,在VB.Net中创建使用控件数组,在Visual Basic .NET 中实现后台进程,VB.NET中使用Directsound9之简单播放,用新VB.NET 枚举提高效率,在有Clipboard的应用程序间移动数据,VB.NET中的变量范围差异,从Visual Basic 6.0 到 Visual Basic.NET 的转换,微软.Net程序设计FAQ
      VB.net

      将所有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;

      }

      }

      }

      在Visual Basic .NET中文件I/O选项
      VB.Net调用存储过程并得到返回值,详解VB.NET对象浏览器作用体现,老生常谈:从VB6迁移到VB.net,VB.net2008精彩实例,窗体应用技巧,用VB.net2008打造你的影音播放器,一个Office 2003风格的通知控件(VB.NET),在VB.NET中操作MySQL数据库,vb.net开发中使用excel插件的代码,vb.net封装组件成com的方法,.NET环境下几种不同的邮件发送解决方案,用.net动态创建类的实例,VB.NET实现DataList横向数据交替变色,在VB.Net中创建使用控件数组,在Visual Basic .NET 中实现后台进程,VB.NET中使用Directsound9之简单播放,用新VB.NET 枚举提高效率,在有Clipboard的应用程序间移动数据,VB.NET中的变量范围差异,从Visual Basic 6.0 到 Visual Basic.NET 的转换,微软.Net程序设计FAQ
      VB.net

    • 0
    • 0
    • 0
    • 62
    • 单栏布局 侧栏位置: