VB.net 2010 视频教程 VB.net 2010 视频教程 VB.net 2010 视频教程
  • vb.net教程之完整的VB.NET的语法解析程序

  • 2017-06-07 15:59 来源:未知
作者: blood 
  比较长,不过支持全部的关键字,直接就可以用了。
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; 
}
}
}

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。

相关教程
  • 西部网(陕西新闻网)www.cnwest.com 2019-01-21
  • 【专家谈】上合组织——构建区域命运共同体的有力实践者 2019-01-21
  • Rich Brian 全新MV《Watch Out!》席卷美国高中Rich Brian 2019-01-21
  • 北美票房:《超人总动员2》重振江湖 2019-01-21
  • 四川积极推进中央环保督察反馈意见整改工作 2019-01-20
  • 金灿荣:特朗普稳住阵脚后或对华更强硬 2019-01-20
  • “任怨”是一种修炼(红船观澜) 2019-01-20
  • 改革开放40年来中国农村发展变化纪实——旧貌换新颜 2019-01-19
  • 广州市第十五届人大常委会第十四次会议第二次全体会议 2019-01-19
  • 办过周永康、孙政才、令计划案的检法机关,拟双双换帅 2019-01-18
  • 解析汽车空调异味漏氟根源 维护需注意这些方面 2019-01-18
  • 六一记忆:不同的年代 同样的快乐 2019-01-17
  • 美司法部认定希拉里“邮件门”调查未受偏见影响 2019-01-17
  • 2013“绿色北京 低碳生活”公益活动顺利落幕 2019-01-17
  • 艾叶泡水喝有哪些食用禁忌? 有哪些食用方式呢 2019-01-17
  • 432| 911| 432| 366| 511| 707| 349| 21| 720| 867|