Created
March 31, 2015 13:28
-
-
Save gnysek/e07825447d67e53ad065 to your computer and use it in GitHub Desktop.
SyntaxHighlighter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Drawing; | |
using System.Text.RegularExpressions; | |
using System.Collections.Generic; | |
using System.Xml; | |
using System.IO; | |
using System; | |
namespace FastColoredTextBoxNS | |
{ | |
public class SyntaxHighlighter: IDisposable | |
{ | |
//styles | |
public readonly Style BlueStyle = new TextStyle(Brushes.Blue, null, FontStyle.Regular); | |
public readonly Style BlueBoldStyle = new TextStyle(Brushes.Blue, null, FontStyle.Bold); | |
public readonly Style BoldStyle = new TextStyle(null, null, FontStyle.Bold | FontStyle.Underline); | |
public readonly Style GrayStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular); | |
public readonly Style MagentaStyle = new TextStyle(Brushes.Magenta, null, FontStyle.Regular); | |
public readonly Style GreenStyle = new TextStyle(Brushes.Green, null, FontStyle.Italic); | |
public readonly Style BrownStyle = new TextStyle(Brushes.Brown, null, FontStyle.Italic); | |
public readonly Style RedStyle = new TextStyle(Brushes.Red, null, FontStyle.Regular); | |
public readonly Style MaroonStyle = new TextStyle(Brushes.Maroon, null, FontStyle.Regular); | |
public readonly Style RedBoldStyle = new TextStyle(Brushes.Red, null, FontStyle.Bold); | |
// | |
Dictionary<string, SyntaxDescriptor> descByXMLfileNames = new Dictionary<string, SyntaxDescriptor>(); | |
static readonly Platform platformType = PlatformType.GetOperationSystemPlatform(); | |
public static RegexOptions RegexCompiledOption | |
{ | |
get { | |
if (platformType == Platform.X86) | |
return RegexOptions.Compiled; | |
else | |
return RegexOptions.None; | |
} | |
} | |
/// <summary> | |
/// Highlights syntax for given language | |
/// </summary> | |
public virtual void HighlightSyntax(Language language, Range range) | |
{ | |
switch (language) | |
{ | |
case Language.CSharp: CSharpSyntaxHighlight(range); break; | |
case Language.VB: VBSyntaxHighlight(range); break; | |
case Language.HTML: HTMLSyntaxHighlight(range); break; | |
case Language.SQL: SQLSyntaxHighlight(range); break; | |
case Language.PHP: PHPSyntaxHighlight(range); break; | |
case Language.JS: JScriptSyntaxHighlight(range); break; | |
case Language.GML: GMLSynaxHighlight(range); break; | |
default: | |
break; | |
} | |
} | |
/// <summary> | |
/// Highlights syntax for given XML description file | |
/// </summary> | |
public virtual void HighlightSyntax(string XMLdescriptionFile, Range range) | |
{ | |
SyntaxDescriptor desc = null; | |
if (!descByXMLfileNames.TryGetValue(XMLdescriptionFile, out desc)) | |
{ | |
var doc = new XmlDocument(); | |
string file = XMLdescriptionFile; | |
if (!File.Exists(file)) | |
file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(file)); | |
doc.LoadXml(File.ReadAllText(file)); | |
desc = ParseXmlDescription(doc); | |
descByXMLfileNames[XMLdescriptionFile] = desc; | |
} | |
HighlightSyntax(desc, range); | |
} | |
public virtual void AutoIndentNeeded(object sender, AutoIndentEventArgs args) | |
{ | |
FastColoredTextBox tb = (sender as FastColoredTextBox); | |
Language language = tb.Language; | |
switch (language) | |
{ | |
case Language.CSharp: CSharpAutoIndentNeeded(sender, args); break; | |
case Language.VB: VBAutoIndentNeeded(sender, args); break; | |
case Language.HTML: HTMLAutoIndentNeeded(sender, args); break; | |
case Language.SQL: SQLAutoIndentNeeded(sender, args); break; | |
case Language.PHP: PHPAutoIndentNeeded(sender, args); break; | |
case Language.JS: CSharpAutoIndentNeeded(sender, args); break;//JS like C# | |
case Language.GML: GMLAutoIndentNeeded(sender, args); break; | |
default: | |
break; | |
} | |
} | |
private void PHPAutoIndentNeeded(object sender, AutoIndentEventArgs args) | |
{ | |
/* | |
FastColoredTextBox tb = sender as FastColoredTextBox; | |
tb.CalcAutoIndentShiftByCodeFolding(sender, args);*/ | |
//block {} | |
if (Regex.IsMatch(args.LineText, @"^[^""']*\{.*\}[^""']*$")) | |
return; | |
//start of block {} | |
if (Regex.IsMatch(args.LineText, @"^[^""']*\{")) | |
{ | |
args.ShiftNextLines = args.TabLength; | |
return; | |
} | |
//end of block {} | |
if (Regex.IsMatch(args.LineText, @"}[^""']*$")) | |
{ | |
args.Shift = -args.TabLength; | |
args.ShiftNextLines = -args.TabLength; | |
return; | |
} | |
//is unclosed operator in previous line ? | |
if (Regex.IsMatch(args.PrevLineText, @"^\s*(if|for|foreach|while|[\}\s]*else)\b[^{]*$")) | |
if (!Regex.IsMatch(args.PrevLineText, @"(;\s*$)|(;\s*//)"))//operator is unclosed | |
{ | |
args.Shift = args.TabLength; | |
return; | |
} | |
} | |
private void GMLAutoIndentNeeded(object sender, AutoIndentEventArgs args) { | |
this.PHPAutoIndentNeeded(sender, args); | |
} | |
private void SQLAutoIndentNeeded(object sender, AutoIndentEventArgs args) | |
{ | |
FastColoredTextBox tb = sender as FastColoredTextBox; | |
tb.CalcAutoIndentShiftByCodeFolding(sender, args); | |
} | |
private void HTMLAutoIndentNeeded(object sender, AutoIndentEventArgs args) | |
{ | |
FastColoredTextBox tb = sender as FastColoredTextBox; | |
tb.CalcAutoIndentShiftByCodeFolding(sender, args); | |
} | |
private void VBAutoIndentNeeded(object sender, AutoIndentEventArgs args) | |
{ | |
//end of block | |
if (Regex.IsMatch(args.LineText, @"^\s*(End|EndIf|Next|Loop)\b", RegexOptions.IgnoreCase)) | |
{ | |
args.Shift = -args.TabLength; | |
args.ShiftNextLines = -args.TabLength; | |
return; | |
} | |
//start of declaration | |
if (Regex.IsMatch(args.LineText, @"\b(Class|Property|Enum|Structure|Sub|Function|Namespace|Interface|Get)\b|(Set\s*\()", RegexOptions.IgnoreCase)) | |
{ | |
args.ShiftNextLines = args.TabLength; | |
return; | |
} | |
// then ... | |
if (Regex.IsMatch(args.LineText, @"\b(Then)\s*\S+", RegexOptions.IgnoreCase)) | |
return; | |
//start of operator block | |
if (Regex.IsMatch(args.LineText, @"^\s*(If|While|For|Do|Try|With|Using|Select)\b", RegexOptions.IgnoreCase)) | |
{ | |
args.ShiftNextLines = args.TabLength; | |
return; | |
} | |
//Statements else, elseif, case etc | |
if (Regex.IsMatch(args.LineText, @"^\s*(Else|ElseIf|Case|Catch|Finally)\b", RegexOptions.IgnoreCase)) | |
{ | |
args.Shift = -args.TabLength; | |
return; | |
} | |
//Char _ | |
if (args.PrevLineText.TrimEnd().EndsWith("_")) | |
{ | |
args.Shift = args.TabLength; | |
return; | |
} | |
} | |
private void CSharpAutoIndentNeeded(object sender, AutoIndentEventArgs args) | |
{ | |
//block {} | |
if (Regex.IsMatch(args.LineText, @"^[^""']*\{.*\}[^""']*$")) | |
return; | |
//start of block {} | |
if (Regex.IsMatch(args.LineText, @"^[^""']*\{")) | |
{ | |
args.ShiftNextLines = args.TabLength; | |
return; | |
} | |
//end of block {} | |
if (Regex.IsMatch(args.LineText, @"}[^""']*$")) | |
{ | |
args.Shift = -args.TabLength; | |
args.ShiftNextLines = -args.TabLength; | |
return; | |
} | |
//label | |
if (Regex.IsMatch(args.LineText, @"^\s*\w+\s*:\s*($|//)") && | |
!Regex.IsMatch(args.LineText, @"^\s*default\s*:")) | |
{ | |
args.Shift = -args.TabLength; | |
return; | |
} | |
//some statements: case, default | |
if (Regex.IsMatch(args.LineText, @"^\s*(case|default)\b.*:\s*($|//)")) | |
{ | |
args.Shift = -args.TabLength/2; | |
return; | |
} | |
//is unclosed operator in previous line ? | |
if (Regex.IsMatch(args.PrevLineText, @"^\s*(if|for|foreach|while|[\}\s]*else)\b[^{]*$")) | |
if (!Regex.IsMatch(args.PrevLineText, @"(;\s*$)|(;\s*//)"))//operator is unclosed | |
{ | |
args.Shift = args.TabLength; | |
return; | |
} | |
} | |
public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc) | |
{ | |
SyntaxDescriptor desc = new SyntaxDescriptor(); | |
XmlNode brackets = doc.SelectSingleNode("doc/brackets"); | |
if (brackets != null) | |
{ | |
if (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null || | |
brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "") | |
{ | |
desc.leftBracket = '\x0'; | |
desc.rightBracket = '\x0'; | |
} | |
else | |
{ | |
desc.leftBracket = brackets.Attributes["left"].Value[0]; | |
desc.rightBracket = brackets.Attributes["right"].Value[0]; | |
} | |
if (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null || | |
brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "") | |
{ | |
desc.leftBracket2 = '\x0'; | |
desc.rightBracket2 = '\x0'; | |
} | |
else | |
{ | |
desc.leftBracket2 = brackets.Attributes["left2"].Value[0]; | |
desc.rightBracket2 = brackets.Attributes["right2"].Value[0]; | |
} | |
} | |
Dictionary<string, Style> styleByName = new Dictionary<string, Style>(); | |
foreach (XmlNode style in doc.SelectNodes("doc/style")) | |
{ | |
var s = ParseStyle(style); | |
styleByName[style.Attributes["name"].Value] = s; | |
desc.styles.Add(s); | |
} | |
foreach (XmlNode rule in doc.SelectNodes("doc/rule")) | |
desc.rules.Add(ParseRule(rule, styleByName)); | |
foreach (XmlNode folding in doc.SelectNodes("doc/folding")) | |
desc.foldings.Add(ParseFolding(folding)); | |
return desc; | |
} | |
private static FoldingDesc ParseFolding(XmlNode foldingNode) | |
{ | |
FoldingDesc folding = new FoldingDesc(); | |
//regex | |
folding.startMarkerRegex = foldingNode.Attributes["start"].Value; | |
folding.finishMarkerRegex = foldingNode.Attributes["finish"].Value; | |
//options | |
var optionsA = foldingNode.Attributes["options"]; | |
if (optionsA != null) | |
folding.options = (RegexOptions)Enum.Parse(typeof(RegexOptions), optionsA.Value); | |
return folding; | |
} | |
private static RuleDesc ParseRule(XmlNode ruleNode, Dictionary<string, Style> styles) | |
{ | |
RuleDesc rule = new RuleDesc(); | |
rule.pattern = ruleNode.InnerText; | |
// | |
var styleA = ruleNode.Attributes["style"]; | |
var optionsA = ruleNode.Attributes["options"]; | |
//Style | |
if (styleA == null) | |
throw new Exception("Rule must contain style name."); | |
if(!styles.ContainsKey(styleA.Value)) | |
throw new Exception("Style '"+styleA.Value+"' is not found."); | |
rule.style = styles[styleA.Value]; | |
//options | |
if (optionsA != null) | |
rule.options = (RegexOptions)Enum.Parse(typeof(RegexOptions), optionsA.Value); | |
return rule; | |
} | |
private static Style ParseStyle(XmlNode styleNode) | |
{ | |
var typeA = styleNode.Attributes["type"]; | |
var colorA = styleNode.Attributes["color"]; | |
var backColorA = styleNode.Attributes["backColor"]; | |
var fontStyleA = styleNode.Attributes["fontStyle"]; | |
var nameA = styleNode.Attributes["name"]; | |
//colors | |
SolidBrush foreBrush = null; | |
if (colorA != null) | |
foreBrush = new SolidBrush(ParseColor(colorA.Value)); | |
SolidBrush backBrush = null; | |
if (backColorA != null) | |
backBrush = new SolidBrush(ParseColor(backColorA.Value)); | |
//fontStyle | |
FontStyle fontStyle = FontStyle.Regular; | |
if (fontStyleA != null) | |
fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), fontStyleA.Value); | |
return new TextStyle(foreBrush, backBrush, fontStyle); | |
} | |
private static Color ParseColor(string s) | |
{ | |
if (s.StartsWith("#")) | |
{ | |
if(s.Length<=7) | |
return Color.FromArgb(255, Color.FromArgb(Int32.Parse(s.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier))); | |
else | |
return Color.FromArgb(Int32.Parse(s.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier)); | |
} | |
else | |
return Color.FromName(s); | |
} | |
public void HighlightSyntax(SyntaxDescriptor desc, Range range) | |
{ | |
//set style order | |
range.tb.ClearStylesBuffer(); | |
for(int i=0;i<desc.styles.Count;i++) | |
range.tb.Styles[i] = desc.styles[i]; | |
//brackets | |
RememberBrackets(); | |
if (range.tb.LeftBracket == null) range.tb.LeftBracket = desc.leftBracket; | |
if (range.tb.RightBracket == null) range.tb.RightBracket = desc.rightBracket; | |
if (range.tb.LeftBracket2 == null) range.tb.LeftBracket2 = desc.leftBracket2; | |
if (range.tb.RightBracket2 == null) range.tb.RightBracket2 = desc.rightBracket2; | |
//clear styles of range | |
range.ClearStyle(desc.styles.ToArray()); | |
//highlight syntax | |
foreach (var rule in desc.rules) | |
range.SetStyle(rule.style, rule.Regex); | |
//clear folding | |
range.ClearFoldingMarkers(); | |
//folding markers | |
foreach (var folding in desc.foldings) | |
range.SetFoldingMarkers(folding.startMarkerRegex, folding.finishMarkerRegex, folding.options); | |
} | |
private void RememberBrackets() | |
{ | |
throw new NotImplementedException(); | |
} | |
Regex CSharpStringRegex, CSharpCommentRegex1, CSharpCommentRegex2, CSharpCommentRegex3, CSharpNumberRegex, CSharpAttributeRegex, CSharpClassNameRegex, CSharpKeywordRegex; | |
void InitCShaprRegex() | |
{ | |
CSharpStringRegex = new Regex( @"""""|@""""|''|@"".*?""|(?<!@)(?<range>"".*?[^\\]"")|'.*?[^\\]'", RegexCompiledOption); | |
CSharpCommentRegex1 = new Regex(@"//.*$", RegexOptions.Multiline | RegexCompiledOption); | |
CSharpCommentRegex2 = new Regex(@"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline | RegexCompiledOption); | |
CSharpCommentRegex3 = new Regex(@"(/\*.*?\*/)|(.*\*/)", RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption); | |
CSharpNumberRegex = new Regex(@"\b\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+\b", RegexCompiledOption); | |
CSharpAttributeRegex = new Regex(@"^\s*(?<range>\[.+?\])\s*$", RegexOptions.Multiline | RegexCompiledOption); | |
CSharpClassNameRegex = new Regex(@"\b(class|struct|enum|interface)\s+(?<range>\w+?)\b", RegexCompiledOption); | |
CSharpKeywordRegex = new Regex(@"\b(abstract|as|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|do|double|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|goto|if|implicit|in|int|interface|internal|is|lock|long|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|virtual|void|volatile|while|add|alias|ascending|descending|dynamic|from|get|global|group|into|join|let|orderby|partial|remove|select|set|value|var|where|yield)\b|#region\b|#endregion\b", RegexCompiledOption); | |
} | |
#region Styles | |
/// <summary> | |
/// String style | |
/// </summary> | |
public Style StringStyle { get; set; } | |
/// <summary> | |
/// Comment style | |
/// </summary> | |
public Style CommentStyle { get; set; } | |
/// <summary> | |
/// Number style | |
/// </summary> | |
public Style NumberStyle { get; set; } | |
/// <summary> | |
/// C# attribute style | |
/// </summary> | |
public Style AttributeStyle { get; set; } | |
/// <summary> | |
/// Class name style | |
/// </summary> | |
public Style ClassNameStyle { get; set; } | |
/// <summary> | |
/// Keyword style | |
/// </summary> | |
public Style KeywordStyle { get; set; } | |
/// <summary> | |
/// Style of tags in comments of C# | |
/// </summary> | |
public Style CommentTagStyle { get; set; } | |
/// <summary> | |
/// HTML attribute value style | |
/// </summary> | |
public Style AttributeValueStyle { get; set; } | |
/// <summary> | |
/// HTML tag brackets style | |
/// </summary> | |
public Style TagBracketStyle { get; set; } | |
/// <summary> | |
/// HTML tag name style | |
/// </summary> | |
public Style TagNameStyle { get; set; } | |
/// <summary> | |
/// HTML Entity style | |
/// </summary> | |
public Style HtmlEntityStyle { get; set; } | |
/// <summary> | |
/// Variable style | |
/// </summary> | |
public Style VariableStyle { get; set; } | |
/// <summary> | |
/// Specific PHP keyword style | |
/// </summary> | |
public Style KeywordStyle2 { get; set; } | |
/// <summary> | |
/// Specific PHP keyword style | |
/// </summary> | |
public Style KeywordStyle3 { get; set; } | |
/// <summary> | |
/// SQL Statements style | |
/// </summary> | |
public Style StatementsStyle { get; set; } | |
/// <summary> | |
/// SQL Functions style | |
/// </summary> | |
public Style FunctionsStyle { get; set; } | |
/// <summary> | |
/// SQL Types style | |
/// </summary> | |
public Style TypesStyle { get; set; } | |
#endregion | |
public void InitStyleSchema(Language lang) | |
{ | |
switch (lang) | |
{ | |
case Language.CSharp: | |
StringStyle = BrownStyle; | |
CommentStyle = GreenStyle; | |
NumberStyle = MagentaStyle; | |
AttributeStyle = GreenStyle; | |
ClassNameStyle = BoldStyle; | |
KeywordStyle = BlueStyle; | |
CommentTagStyle = GrayStyle; | |
break; | |
case Language.VB: | |
StringStyle = BrownStyle; | |
CommentStyle = GreenStyle; | |
NumberStyle = MagentaStyle; | |
ClassNameStyle = BoldStyle; | |
KeywordStyle = BlueStyle; | |
break; | |
case Language.HTML: | |
CommentStyle = GreenStyle; | |
TagBracketStyle = BlueStyle; | |
TagNameStyle = MaroonStyle; | |
AttributeStyle = RedStyle; | |
AttributeValueStyle = BlueStyle; | |
HtmlEntityStyle = RedStyle; | |
break; | |
case Language.JS: | |
StringStyle = BrownStyle; | |
CommentStyle = GreenStyle; | |
NumberStyle = MagentaStyle; | |
KeywordStyle = BlueStyle; | |
KeywordStyle = BlueStyle; | |
break; | |
case Language.PHP: | |
StringStyle = RedStyle; | |
CommentStyle = GreenStyle; | |
NumberStyle = RedStyle; | |
VariableStyle = MaroonStyle; | |
KeywordStyle = MagentaStyle; | |
KeywordStyle2 = BlueStyle; | |
KeywordStyle3 = GrayStyle; | |
break; | |
case Language.SQL: | |
StringStyle = RedStyle; | |
CommentStyle = GreenStyle; | |
NumberStyle = MagentaStyle; | |
KeywordStyle = BlueStyle; | |
StatementsStyle = BlueBoldStyle; | |
FunctionsStyle = MaroonStyle; | |
VariableStyle = MaroonStyle; | |
TypesStyle = BrownStyle; | |
break; | |
case Language.GML: | |
StringStyle = RedStyle; | |
CommentStyle = GreenStyle; | |
NumberStyle = BlueStyle; | |
VariableStyle = MaroonStyle; | |
KeywordStyle = RedBoldStyle; | |
KeywordStyle2 = BlueStyle; | |
KeywordStyle3 = MagentaStyle; | |
break; | |
} | |
} | |
/// <summary> | |
/// Highlights C# code | |
/// </summary> | |
/// <param name="range"></param> | |
public virtual void CSharpSyntaxHighlight(Range range) | |
{ | |
range.tb.CommentPrefix = "//"; | |
range.tb.LeftBracket = '('; | |
range.tb.RightBracket = ')'; | |
range.tb.LeftBracket2 = '\x0'; | |
range.tb.RightBracket2 = '\x0'; | |
//clear style of changed range | |
range.ClearStyle(StringStyle, CommentStyle, NumberStyle, AttributeStyle, ClassNameStyle, KeywordStyle); | |
// | |
if (CSharpStringRegex == null) | |
InitCShaprRegex(); | |
//string highlighting | |
range.SetStyle(StringStyle, CSharpStringRegex); | |
//comment highlighting | |
range.SetStyle(CommentStyle, CSharpCommentRegex1); | |
range.SetStyle(CommentStyle, CSharpCommentRegex2); | |
range.SetStyle(CommentStyle, CSharpCommentRegex3); | |
//number highlighting | |
range.SetStyle(NumberStyle, CSharpNumberRegex); | |
//attribute highlighting | |
range.SetStyle(AttributeStyle, CSharpAttributeRegex); | |
//class name highlighting | |
range.SetStyle(ClassNameStyle, CSharpClassNameRegex); | |
//keyword highlighting | |
range.SetStyle(KeywordStyle, CSharpKeywordRegex); | |
//find document comments | |
foreach (var r in range.GetRanges(@"^\s*///.*$", RegexOptions.Multiline)) | |
{ | |
//remove C# highlighting from this fragment | |
r.ClearStyle(StyleIndex.All); | |
//do XML highlighting | |
if (HTMLTagRegex == null) | |
InitHTMLRegex(); | |
// | |
r.SetStyle(CommentStyle); | |
//tags | |
foreach (var rr in r.GetRanges(HTMLTagContentRegex)) | |
{ | |
rr.ClearStyle(StyleIndex.All); | |
rr.SetStyle(CommentTagStyle); | |
} | |
//prefix '///' | |
foreach (var rr in r.GetRanges( @"^\s*///", RegexOptions.Multiline)) | |
{ | |
rr.ClearStyle(StyleIndex.All); | |
rr.SetStyle(CommentTagStyle); | |
} | |
} | |
//clear folding markers | |
range.ClearFoldingMarkers(); | |
//set folding markers | |
range.SetFoldingMarkers("{", "}");//allow to collapse brackets block | |
range.SetFoldingMarkers(@"#region\b", @"#endregion\b");//allow to collapse #region blocks | |
range.SetFoldingMarkers(@"/\*", @"\*/");//allow to collapse comment block | |
} | |
Regex VBStringRegex, VBCommentRegex, VBNumberRegex, VBClassNameRegex, VBKeywordRegex; | |
void InitVBRegex() | |
{ | |
VBStringRegex = new Regex(@"""""|"".*?[^\\]""", RegexCompiledOption); | |
VBCommentRegex = new Regex(@"'.*$", RegexOptions.Multiline | RegexCompiledOption); | |
VBNumberRegex = new Regex(@"\b\d+[\.]?\d*([eE]\-?\d+)?\b", RegexCompiledOption); | |
VBClassNameRegex = new Regex(@"\b(Class|Structure|Enum|Interface)[ ]+(?<range>\w+?)\b", RegexOptions.IgnoreCase | RegexCompiledOption); | |
VBKeywordRegex = new Regex(@"\b(AddHandler|AddressOf|Alias|And|AndAlso|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDbl|CDec|Char|CInt|Class|CLng|CObj|Const|Continue|CSByte|CShort|CSng|CStr|CType|CUInt|CULng|CUShort|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|False|Finally|For|Friend|Function|Get|GetType|GetXMLNamespace|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|MustInherit|MustOverride|MyBase|MyClass|Namespace|Narrowing|New|Next|Not|Nothing|NotInheritable|NotOverridable|Object|Of|On|Operator|Option|Optional|Or|OrElse|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|REM|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|Short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|True|Try|TryCast|TypeOf|UInteger|ULong|UShort|Using|Variant|Wend|When|While|Widening|With|WithEvents|WriteOnly|Xor|Region)\b|(#Const|#Else|#ElseIf|#End|#If|#Region)\b", RegexOptions.IgnoreCase | RegexCompiledOption); | |
} | |
/// <summary> | |
/// Highlights VB code | |
/// </summary> | |
/// <param name="range"></param> | |
public virtual void VBSyntaxHighlight(Range range) | |
{ | |
range.tb.CommentPrefix = "'"; | |
range.tb.LeftBracket = '('; | |
range.tb.RightBracket = ')'; | |
range.tb.LeftBracket2 = '\x0'; | |
range.tb.RightBracket2 = '\x0'; | |
//clear style of changed range | |
range.ClearStyle(StringStyle, CommentStyle, NumberStyle, ClassNameStyle, KeywordStyle); | |
// | |
if (VBStringRegex == null) | |
InitVBRegex(); | |
//string highlighting | |
range.SetStyle(StringStyle, VBStringRegex); | |
//comment highlighting | |
range.SetStyle(CommentStyle, VBCommentRegex); | |
//number highlighting | |
range.SetStyle(NumberStyle, VBNumberRegex); | |
//class name highlighting | |
range.SetStyle(ClassNameStyle, VBClassNameRegex); | |
//keyword highlighting | |
range.SetStyle(KeywordStyle, VBKeywordRegex); | |
//clear folding markers | |
range.ClearFoldingMarkers(); | |
//set folding markers | |
range.SetFoldingMarkers(@"#Region\b", @"#End\s+Region\b", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers(@"\b(Class|Property|Enum|Structure|Interface)[ \t]+\S+", @"\bEnd (Class|Property|Enum|Structure|Interface)\b", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers(@"^\s*(?<range>While)[ \t]+\S+", @"^\s*(?<range>End While)\b", RegexOptions.Multiline | RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers(@"\b(Sub|Function)[ \t]+[^\s']+", @"\bEnd (Sub|Function)\b", RegexOptions.IgnoreCase);//this declared separately because Sub and Function can be unclosed | |
range.SetFoldingMarkers(@"(\r|\n|^)[ \t]*(?<range>Get|Set)[ \t]*(\r|\n|$)", @"\bEnd (Get|Set)\b", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers(@"^\s*(?<range>For|For\s+Each)\b", @"^\s*(?<range>Next)\b", RegexOptions.Multiline | RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers(@"^\s*(?<range>Do)\b", @"^\s*(?<range>Loop)\b", RegexOptions.Multiline | RegexOptions.IgnoreCase); | |
} | |
Regex HTMLTagRegex, HTMLTagNameRegex, HTMLEndTagRegex, HTMLAttrRegex, HTMLAttrValRegex, HTMLCommentRegex1, HTMLCommentRegex2, HTMLEntityRegex, HTMLTagContentRegex; | |
void InitHTMLRegex() | |
{ | |
HTMLCommentRegex1 = new Regex(@"(<!--.*?-->)|(<!--.*)", RegexOptions.Singleline | RegexCompiledOption); | |
HTMLCommentRegex2 = new Regex(@"(<!--.*?-->)|(.*-->)", RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption); | |
HTMLTagRegex = new Regex(@"<|/>|</|>", RegexCompiledOption); | |
HTMLTagNameRegex = new Regex(@"<(?<range>[!\w:]+)", RegexCompiledOption); | |
HTMLEndTagRegex = new Regex(@"</(?<range>[\w:]+)>", RegexCompiledOption); | |
HTMLTagContentRegex = new Regex(@"<[^>]+>", RegexCompiledOption); | |
HTMLAttrRegex = new Regex(@"(?<range>[\w\d\-]{1,20}?)='[^']*'|(?<range>[\w\d\-]{1,20})=""[^""]*""|(?<range>[\w\d\-]{1,20})=[\w\d\-]{1,20}", RegexCompiledOption); | |
HTMLAttrValRegex = new Regex(@"[\w\d\-]{1,20}?=(?<range>'[^']*')|[\w\d\-]{1,20}=(?<range>""[^""]*"")|[\w\d\-]{1,20}=(?<range>[\w\d\-]{1,20})", RegexCompiledOption); | |
HTMLEntityRegex = new Regex(@"\&(amp|gt|lt|nbsp|quot|apos|copy|reg|#[0-9]{1,8}|#x[0-9a-f]{1,8});", RegexCompiledOption | RegexOptions.IgnoreCase); | |
} | |
/// <summary> | |
/// Highlights HTML code | |
/// </summary> | |
/// <param name="range"></param> | |
public virtual void HTMLSyntaxHighlight(Range range) | |
{ | |
range.tb.CommentPrefix = null; | |
range.tb.LeftBracket = '<'; | |
range.tb.RightBracket = '>'; | |
range.tb.LeftBracket2 = '('; | |
range.tb.RightBracket2 = ')'; | |
//clear style of changed range | |
range.ClearStyle(CommentStyle, TagBracketStyle, TagNameStyle, AttributeStyle, AttributeValueStyle, HtmlEntityStyle); | |
// | |
if (HTMLTagRegex == null) | |
InitHTMLRegex(); | |
//comment highlighting | |
range.SetStyle(CommentStyle, HTMLCommentRegex1); | |
range.SetStyle(CommentStyle, HTMLCommentRegex2); | |
//tag brackets highlighting | |
range.SetStyle(TagBracketStyle, HTMLTagRegex); | |
//tag name | |
range.SetStyle(TagNameStyle, HTMLTagNameRegex); | |
//end of tag | |
range.SetStyle(TagNameStyle, HTMLEndTagRegex); | |
//attributes | |
range.SetStyle(AttributeStyle, HTMLAttrRegex); | |
//attribute values | |
range.SetStyle(AttributeValueStyle, HTMLAttrValRegex); | |
//html entity | |
range.SetStyle(HtmlEntityStyle, HTMLEntityRegex); | |
//clear folding markers | |
range.ClearFoldingMarkers(); | |
//set folding markers | |
range.SetFoldingMarkers("<head", "</head>", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers("<body", "</body>", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers("<table", "</table>", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers("<form", "</form>", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers("<div", "</div>", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers("<script", "</script>", RegexOptions.IgnoreCase); | |
range.SetFoldingMarkers("<tr", "</tr>", RegexOptions.IgnoreCase); | |
} | |
Regex SQLStringRegex, SQLNumberRegex, SQLCommentRegex1, SQLCommentRegex2, SQLCommentRegex3, SQLVarRegex, SQLStatementsRegex, SQLKeywordsRegex, SQLFunctionsRegex, SQLTypesRegex; | |
void InitSQLRegex() | |
{ | |
SQLStringRegex = new Regex(@"""""|''|"".*?[^\\]""|'.*?[^\\]'", RegexCompiledOption); | |
SQLNumberRegex = new Regex(@"\b\d+[\.]?\d*([eE]\-?\d+)?\b", RegexCompiledOption); | |
SQLCommentRegex1 = new Regex(@"--.*$", RegexOptions.Multiline | RegexCompiledOption); | |
SQLCommentRegex2 = new Regex(@"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline | RegexCompiledOption); | |
SQLCommentRegex3 = new Regex(@"(/\*.*?\*/)|(.*\*/)", RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption); | |
SQLVarRegex = new Regex(@"@[a-zA-Z_\d]*\b", RegexCompiledOption); | |
SQLStatementsRegex = new Regex(@"\b(ALTER APPLICATION ROLE|ALTER ASSEMBLY|ALTER ASYMMETRIC KEY|ALTER AUTHORIZATION|ALTER BROKER PRIORITY|ALTER CERTIFICATE|ALTER CREDENTIAL|ALTER CRYPTOGRAPHIC PROVIDER|ALTER DATABASE|ALTER DATABASE AUDIT SPECIFICATION|ALTER DATABASE ENCRYPTION KEY|ALTER ENDPOINT|ALTER EVENT SESSION|ALTER FULLTEXT CATALOG|ALTER FULLTEXT INDEX|ALTER FULLTEXT STOPLIST|ALTER FUNCTION|ALTER INDEX|ALTER LOGIN|ALTER MASTER KEY|ALTER MESSAGE TYPE|ALTER PARTITION FUNCTION|ALTER PARTITION SCHEME|ALTER PROCEDURE|ALTER QUEUE|ALTER REMOTE SERVICE BINDING|ALTER RESOURCE GOVERNOR|ALTER RESOURCE POOL|ALTER ROLE|ALTER ROUTE|ALTER SCHEMA|ALTER SERVER AUDIT|ALTER SERVER AUDIT SPECIFICATION|ALTER SERVICE|ALTER SERVICE MASTER KEY|ALTER SYMMETRIC KEY|ALTER TABLE|ALTER TRIGGER|ALTER USER|ALTER VIEW|ALTER WORKLOAD GROUP|ALTER XML SCHEMA COLLECTION|BULK INSERT|CREATE AGGREGATE|CREATE APPLICATION ROLE|CREATE ASSEMBLY|CREATE ASYMMETRIC KEY|CREATE BROKER PRIORITY|CREATE CERTIFICATE|CREATE CONTRACT|CREATE CREDENTIAL|CREATE CRYPTOGRAPHIC PROVIDER|CREATE DATABASE|CREATE DATABASE AUDIT SPECIFICATION|CREATE DATABASE ENCRYPTION KEY|CREATE DEFAULT|CREATE ENDPOINT|CREATE EVENT NOTIFICATION|CREATE EVENT SESSION|CREATE FULLTEXT CATALOG|CREATE FULLTEXT INDEX|CREATE FULLTEXT STOPLIST|CREATE FUNCTION|CREATE INDEX|CREATE LOGIN|CREATE MASTER KEY|CREATE MESSAGE TYPE|CREATE PARTITION FUNCTION|CREATE PARTITION SCHEME|CREATE PROCEDURE|CREATE QUEUE|CREATE REMOTE SERVICE BINDING|CREATE RESOURCE POOL|CREATE ROLE|CREATE ROUTE|CREATE RULE|CREATE SCHEMA|CREATE SERVER AUDIT|CREATE SERVER AUDIT SPECIFICATION|CREATE SERVICE|CREATE SPATIAL INDEX|CREATE STATISTICS|CREATE SYMMETRIC KEY|CREATE SYNONYM|CREATE TABLE|CREATE TRIGGER|CREATE TYPE|CREATE USER|CREATE VIEW|CREATE WORKLOAD GROUP|CREATE XML INDEX|CREATE XML SCHEMA COLLECTION|DELETE|DISABLE TRIGGER|DROP AGGREGATE|DROP APPLICATION ROLE|DROP ASSEMBLY|DROP ASYMMETRIC KEY|DROP BROKER PRIORITY|DROP CERTIFICATE|DROP CONTRACT|DROP CREDENTIAL|DROP CRYPTOGRAPHIC PROVIDER|DROP DATABASE|DROP DATABASE AUDIT SPECIFICATION|DROP DATABASE ENCRYPTION KEY|DROP DEFAULT|DROP ENDPOINT|DROP EVENT NOTIFICATION|DROP EVENT SESSION|DROP FULLTEXT CATALOG|DROP FULLTEXT INDEX|DROP FULLTEXT STOPLIST|DROP FUNCTION|DROP INDEX|DROP LOGIN|DROP MASTER KEY|DROP MESSAGE TYPE|DROP PARTITION FUNCTION|DROP PARTITION SCHEME|DROP PROCEDURE|DROP QUEUE|DROP REMOTE SERVICE BINDING|DROP RESOURCE POOL|DROP ROLE|DROP ROUTE|DROP RULE|DROP SCHEMA|DROP SERVER AUDIT|DROP SERVER AUDIT SPECIFICATION|DROP SERVICE|DROP SIGNATURE|DROP STATISTICS|DROP SYMMETRIC KEY|DROP SYNONYM|DROP TABLE|DROP TRIGGER|DROP TYPE|DROP USER|DROP VIEW|DROP WORKLOAD GROUP|DROP XML SCHEMA COLLECTION|ENABLE TRIGGER|EXEC|EXECUTE|FROM|INSERT|MERGE|OPTION|OUTPUT|SELECT|TOP|TRUNCATE TABLE|UPDATE|UPDATE STATISTICS|WHERE|WITH)\b", RegexOptions.IgnoreCase | RegexCompiledOption); | |
SQLKeywordsRegex = new Regex(@"\b(ADD|ALL|AND|ANY|AS|ASC|AUTHORIZATION|BACKUP|BEGIN|BETWEEN|BREAK|BROWSE|BY|CASCADE|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COLLATE|COLUMN|COMMIT|COMPUTE|CONSTRAINT|CONTAINS|CONTINUE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURSOR|DATABASE|DBCC|DEALLOCATE|DECLARE|DEFAULT|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DUMP|ELSE|END|ERRLVL|ESCAPE|EXCEPT|EXISTS|EXIT|EXTERNAL|FETCH|FILE|FILLFACTOR|FOR|FOREIGN|FREETEXT|FULL|FUNCTION|GOTO|GRANT|GROUP|HAVING|HOLDLOCK|IDENTITY|IDENTITY_INSERT|IDENTITYCOL|IF|IN|INDEX|INNER|INTERSECT|INTO|IS|JOIN|KEY|KILL|LIKE|LINENO|LOAD|NATIONAL|NOCHECK|NONCLUSTERED|NOT|NULL|OF|OFF|OFFSETS|ON|OPEN|OR|ORDER|OUTER|OVER|PERCENT|PIVOT|PLAN|PRECISION|PRIMARY|PRINT|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|RECONFIGURE|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|REVERT|REVOKE|ROLLBACK|ROWCOUNT|ROWGUIDCOL|RULE|SAVE|SCHEMA|SECURITYAUDIT|SET|SHUTDOWN|SOME|STATISTICS|TABLE|TABLESAMPLE|TEXTSIZE|THEN|TO|TRAN|TRANSACTION|TRIGGER|TSEQUAL|UNION|UNIQUE|UNPIVOT|UPDATETEXT|USE|USER|VALUES|VARYING|VIEW|WAITFOR|WHEN|WHILE|WRITETEXT)\b", RegexOptions.IgnoreCase | RegexCompiledOption); | |
SQLFunctionsRegex = new Regex(@"(@@CONNECTIONS|@@CPU_BUSY|@@CURSOR_ROWS|@@DATEFIRST|@@DATEFIRST|@@DBTS|@@ERROR|@@FETCH_STATUS|@@IDENTITY|@@IDLE|@@IO_BUSY|@@LANGID|@@LANGUAGE|@@LOCK_TIMEOUT|@@MAX_CONNECTIONS|@@MAX_PRECISION|@@NESTLEVEL|@@OPTIONS|@@PACKET_ERRORS|@@PROCID|@@REMSERVER|@@ROWCOUNT|@@SERVERNAME|@@SERVICENAME|@@SPID|@@TEXTSIZE|@@TRANCOUNT|@@VERSION)\b|\b(ABS|ACOS|APP_NAME|ASCII|ASIN|ASSEMBLYPROPERTY|AsymKey_ID|ASYMKEY_ID|asymkeyproperty|ASYMKEYPROPERTY|ATAN|ATN2|AVG|CASE|CAST|CEILING|Cert_ID|Cert_ID|CertProperty|CHAR|CHARINDEX|CHECKSUM_AGG|COALESCE|COL_LENGTH|COL_NAME|COLLATIONPROPERTY|COLLATIONPROPERTY|COLUMNPROPERTY|COLUMNS_UPDATED|COLUMNS_UPDATED|CONTAINSTABLE|CONVERT|COS|COT|COUNT|COUNT_BIG|CRYPT_GEN_RANDOM|CURRENT_TIMESTAMP|CURRENT_TIMESTAMP|CURRENT_USER|CURRENT_USER|CURSOR_STATUS|DATABASE_PRINCIPAL_ID|DATABASE_PRINCIPAL_ID|DATABASEPROPERTY|DATABASEPROPERTYEX|DATALENGTH|DATALENGTH|DATEADD|DATEDIFF|DATENAME|DATEPART|DAY|DB_ID|DB_NAME|DECRYPTBYASYMKEY|DECRYPTBYCERT|DECRYPTBYKEY|DECRYPTBYKEYAUTOASYMKEY|DECRYPTBYKEYAUTOCERT|DECRYPTBYPASSPHRASE|DEGREES|DENSE_RANK|DIFFERENCE|ENCRYPTBYASYMKEY|ENCRYPTBYCERT|ENCRYPTBYKEY|ENCRYPTBYPASSPHRASE|ERROR_LINE|ERROR_MESSAGE|ERROR_NUMBER|ERROR_PROCEDURE|ERROR_SEVERITY|ERROR_STATE|EVENTDATA|EXP|FILE_ID|FILE_IDEX|FILE_NAME|FILEGROUP_ID|FILEGROUP_NAME|FILEGROUPPROPERTY|FILEPROPERTY|FLOOR|fn_helpcollations|fn_listextendedproperty|fn_servershareddrives|fn_virtualfilestats|fn_virtualfilestats|FORMATMESSAGE|FREETEXTTABLE|FULLTEXTCATALOGPROPERTY|FULLTEXTSERVICEPROPERTY|GETANSINULL|GETDATE|GETUTCDATE|GROUPING|HAS_PERMS_BY_NAME|HOST_ID|HOST_NAME|IDENT_CURRENT|IDENT_CURRENT|IDENT_INCR|IDENT_INCR|IDENT_SEED|IDENTITY\(|INDEX_COL|INDEXKEY_PROPERTY|INDEXPROPERTY|IS_MEMBER|IS_OBJECTSIGNED|IS_SRVROLEMEMBER|ISDATE|ISDATE|ISNULL|ISNUMERIC|Key_GUID|Key_GUID|Key_ID|Key_ID|KEY_NAME|KEY_NAME|LEFT|LEN|LOG|LOG10|LOWER|LTRIM|MAX|MIN|MONTH|NCHAR|NEWID|NTILE|NULLIF|OBJECT_DEFINITION|OBJECT_ID|OBJECT_NAME|OBJECT_SCHEMA_NAME|OBJECTPROPERTY|OBJECTPROPERTYEX|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|ORIGINAL_LOGIN|ORIGINAL_LOGIN|PARSENAME|PATINDEX|PATINDEX|PERMISSIONS|PI|POWER|PUBLISHINGSERVERNAME|PWDCOMPARE|PWDENCRYPT|QUOTENAME|RADIANS|RAND|RANK|REPLACE|REPLICATE|REVERSE|RIGHT|ROUND|ROW_NUMBER|ROWCOUNT_BIG|RTRIM|SCHEMA_ID|SCHEMA_ID|SCHEMA_NAME|SCHEMA_NAME|SCOPE_IDENTITY|SERVERPROPERTY|SESSION_USER|SESSION_USER|SESSIONPROPERTY|SETUSER|SIGN|SignByAsymKey|SignByCert|SIN|SOUNDEX|SPACE|SQL_VARIANT_PROPERTY|SQRT|SQUARE|STATS_DATE|STDEV|STDEVP|STR|STUFF|SUBSTRING|SUM|SUSER_ID|SUSER_NAME|SUSER_SID|SUSER_SNAME|SWITCHOFFSET|SYMKEYPROPERTY|symkeyproperty|sys\.dm_db_index_physical_stats|sys\.fn_builtin_permissions|sys\.fn_my_permissions|SYSDATETIME|SYSDATETIMEOFFSET|SYSTEM_USER|SYSTEM_USER|SYSUTCDATETIME|TAN|TERTIARY_WEIGHTS|TEXTPTR|TODATETIMEOFFSET|TRIGGER_NESTLEVEL|TYPE_ID|TYPE_NAME|TYPEPROPERTY|UNICODE|UPDATE\(|UPPER|USER_ID|USER_NAME|USER_NAME|VAR|VARP|VerifySignedByAsymKey|VerifySignedByCert|XACT_STATE|YEAR)\b", RegexOptions.IgnoreCase | RegexCompiledOption); | |
SQLTypesRegex = new Regex(@"\b(BIGINT|NUMERIC|BIT|SMALLINT|DECIMAL|SMALLMONEY|INT|TINYINT|MONEY|FLOAT|REAL|DATE|DATETIMEOFFSET|DATETIME2|SMALLDATETIME|DATETIME|TIME|CHAR|VARCHAR|TEXT|NCHAR|NVARCHAR|NTEXT|BINARY|VARBINARY|IMAGE|TIMESTAMP|HIERARCHYID|TABLE|UNIQUEIDENTIFIER|SQL_VARIANT|XML)\b", RegexOptions.IgnoreCase | RegexCompiledOption); | |
} | |
/// <summary> | |
/// Highlights SQL code | |
/// </summary> | |
/// <param name="range"></param> | |
public virtual void SQLSyntaxHighlight(Range range) | |
{ | |
range.tb.CommentPrefix = "--"; | |
range.tb.LeftBracket = '('; | |
range.tb.RightBracket = ')'; | |
range.tb.LeftBracket2 = '\x0'; | |
range.tb.RightBracket2 = '\x0'; | |
//clear style of changed range | |
range.ClearStyle(CommentStyle, StringStyle, NumberStyle, VariableStyle, StatementsStyle, KeywordStyle, FunctionsStyle, TypesStyle); | |
// | |
if (SQLStringRegex == null) | |
InitSQLRegex(); | |
//comment highlighting | |
range.SetStyle(CommentStyle, SQLCommentRegex1); | |
range.SetStyle(CommentStyle, SQLCommentRegex2); | |
range.SetStyle(CommentStyle, SQLCommentRegex3); | |
//string highlighting | |
range.SetStyle(StringStyle, SQLStringRegex); | |
//number highlighting | |
range.SetStyle(NumberStyle, SQLNumberRegex); | |
//types highlighting | |
range.SetStyle(TypesStyle, SQLTypesRegex); | |
//var highlighting | |
range.SetStyle(VariableStyle, SQLVarRegex); | |
//statements | |
range.SetStyle(StatementsStyle, SQLStatementsRegex); | |
//keywords | |
range.SetStyle(KeywordStyle, SQLKeywordsRegex); | |
//functions | |
range.SetStyle(FunctionsStyle, SQLFunctionsRegex); | |
//clear folding markers | |
range.ClearFoldingMarkers(); | |
//set folding markers | |
range.SetFoldingMarkers(@"\bBEGIN\b", @"\bEND\b", RegexOptions.IgnoreCase);//allow to collapse BEGIN..END blocks | |
range.SetFoldingMarkers(@"/\*", @"\*/");//allow to collapse comment block | |
} | |
Regex PHPStringRegex, PHPNumberRegex, PHPCommentRegex1, PHPCommentRegex2, PHPCommentRegex3, PHPVarRegex, PHPKeywordRegex1, PHPKeywordRegex2, PHPKeywordRegex3; | |
void InitPHPRegex() | |
{ | |
PHPStringRegex = new Regex(@"""""|''|"".*?[^\\]""|'.*?[^\\]'", RegexCompiledOption); | |
PHPNumberRegex = new Regex(@"\b\d+[\.]?\d*\b", RegexCompiledOption); | |
PHPCommentRegex1 = new Regex(@"(//|#).*$", RegexOptions.Multiline | RegexCompiledOption); | |
PHPCommentRegex2 = new Regex(@"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline | RegexCompiledOption); | |
PHPCommentRegex3 = new Regex(@"(/\*.*?\*/)|(.*\*/)", RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption); | |
PHPVarRegex = new Regex(@"\$[a-zA-Z_\d]*\b", RegexCompiledOption); | |
PHPKeywordRegex1 = new Regex(@"\b(die|echo|empty|exit|eval|include|include_once|isset|list|require|require_once|return|print|unset)\b", RegexCompiledOption); | |
PHPKeywordRegex2 = new Regex(@"\b(abstract|and|array|as|break|case|catch|cfunction|class|clone|const|continue|declare|default|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|final|for|foreach|function|global|goto|if|implements|instanceof|interface|namespace|new|or|private|protected|public|static|switch|throw|try|use|var|while|xor)\b", RegexCompiledOption); | |
PHPKeywordRegex3 = new Regex(@"__CLASS__|__DIR__|__FILE__|__LINE__|__FUNCTION__|__METHOD__|__NAMESPACE__", RegexCompiledOption); | |
} | |
/// <summary> | |
/// Highlights PHP code | |
/// </summary> | |
/// <param name="range"></param> | |
public virtual void PHPSyntaxHighlight(Range range) | |
{ | |
range.tb.CommentPrefix = "#"; | |
range.tb.LeftBracket = '('; | |
range.tb.RightBracket = ')'; | |
range.tb.LeftBracket2 = '\x0'; | |
range.tb.RightBracket2 = '\x0'; | |
//clear style of changed range | |
range.ClearStyle(StringStyle, CommentStyle, NumberStyle, VariableStyle, KeywordStyle, KeywordStyle2, KeywordStyle3); | |
// | |
if (PHPStringRegex == null) | |
InitPHPRegex(); | |
//string highlighting | |
range.SetStyle(StringStyle, PHPStringRegex); | |
//comment highlighting | |
range.SetStyle(CommentStyle, PHPCommentRegex1); | |
range.SetStyle(CommentStyle, PHPCommentRegex2); | |
range.SetStyle(CommentStyle, PHPCommentRegex3); | |
//number highlighting | |
range.SetStyle(NumberStyle, PHPNumberRegex); | |
//var highlighting | |
range.SetStyle(VariableStyle, PHPVarRegex); | |
//keyword highlighting | |
range.SetStyle(KeywordStyle, PHPKeywordRegex1); | |
range.SetStyle(KeywordStyle2, PHPKeywordRegex2); | |
range.SetStyle(KeywordStyle3, PHPKeywordRegex3); | |
//clear folding markers | |
range.ClearFoldingMarkers(); | |
//set folding markers | |
range.SetFoldingMarkers("{", "}");//allow to collapse brackets block | |
range.SetFoldingMarkers(@"/\*", @"\*/");//allow to collapse comment block | |
} | |
Regex JScriptStringRegex, JScriptCommentRegex1, JScriptCommentRegex2, JScriptCommentRegex3, JScriptNumberRegex, JScriptKeywordRegex; | |
void InitJScriptRegex() | |
{ | |
JScriptStringRegex = new Regex(@"""""|''|"".*?[^\\]""|'.*?[^\\]'", RegexCompiledOption); | |
JScriptCommentRegex1 = new Regex(@"//.*$", RegexOptions.Multiline | RegexCompiledOption); | |
JScriptCommentRegex2 = new Regex(@"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline | RegexCompiledOption); | |
JScriptCommentRegex3 = new Regex(@"(/\*.*?\*/)|(.*\*/)", RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption); | |
JScriptNumberRegex = new Regex(@"\b\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+\b", RegexCompiledOption); | |
JScriptKeywordRegex = new Regex(@"\b(true|false|break|case|catch|const|continue|default|delete|do|else|export|for|function|if|in|instanceof|new|null|return|switch|this|throw|try|var|void|while|with|typeof)\b", RegexCompiledOption); | |
} | |
/// <summary> | |
/// Highlights JavaScript code | |
/// </summary> | |
/// <param name="range"></param> | |
public virtual void JScriptSyntaxHighlight(Range range) | |
{ | |
range.tb.CommentPrefix = "//"; | |
range.tb.LeftBracket = '('; | |
range.tb.RightBracket = ')'; | |
range.tb.LeftBracket2 = '\x0'; | |
range.tb.RightBracket2 = '\x0'; | |
//clear style of changed range | |
range.ClearStyle(StringStyle, CommentStyle, NumberStyle, KeywordStyle); | |
// | |
if (JScriptStringRegex == null) | |
InitJScriptRegex(); | |
//string highlighting | |
range.SetStyle(StringStyle, JScriptStringRegex); | |
//comment highlighting | |
range.SetStyle(CommentStyle, JScriptCommentRegex1); | |
range.SetStyle(CommentStyle, JScriptCommentRegex2); | |
range.SetStyle(CommentStyle, JScriptCommentRegex3); | |
//number highlighting | |
range.SetStyle(NumberStyle, JScriptNumberRegex); | |
//keyword highlighting | |
range.SetStyle(KeywordStyle, JScriptKeywordRegex); | |
//clear folding markers | |
range.ClearFoldingMarkers(); | |
//set folding markers | |
range.SetFoldingMarkers("{", "}");//allow to collapse brackets block | |
range.SetFoldingMarkers(@"/\*", @"\*/");//allow to collapse comment block | |
} | |
Regex GMLKeywordRegex, GMLStringRegex, GMLFunctionsRegex, GMLNumberRegex, GMLReadOnlyRegex; | |
void InitGMLRegex() | |
{ | |
GMLNumberRegex = new Regex(@"(\$[0-9A-F]+|\d+[\.]?\d*)", RegexCompiledOption); | |
GMLStringRegex = new Regex(@"""""|''|"".*?[^\\]""|'.*?[^\\]'", RegexCompiledOption); | |
GMLFunctionsRegex = new Regex(@"\b(is_real|is_string|is_array|is_undefined|is_int32|is_int64|is_ptr|is_vec3|is_vec4|is_matrix|array_length_1d|array_length_2d|array_height_2d|random|random_range|irandom|irandom_range|random_set_seed|random_get_seed|randomize|choose|abs|round|floor|ceil|sign|frac|sqrt|sqr|exp|ln|log2|log10|sin|cos|tan|arcsin|arccos|arctan|arctan2|dsin|dcos|dtan|darcsin|darccos|darctan|darctan2|degtorad|radtodeg|power|logn|min|max|mean|median|clamp|lerp|dot_product|dot_product_3d|dot_product_normalised|dot_product_3d_normalised|math_set_epsilon|angle_difference|point_distance_3d|point_distance|point_direction|lengthdir_x|lengthdir_y|real|string|string_format|chr|ansi_char|ord|string_length|string_byte_length|string_pos|string_copy|string_char_at|string_byte_at|string_set_byte_at|string_delete|string_insert|string_lower|string_upper|string_repeat|string_letters|string_digits|string_lettersdigits|string_replace|string_replace_all|string_count|clipboard_has_text|clipboard_set_text|clipboard_get_text|date_current_datetime|date_create_datetime|date_valid_datetime|date_inc_year|date_inc_month|date_inc_week|date_inc_day|date_inc_hour|date_inc_minute|date_inc_second|date_get_year|date_get_month|date_get_week|date_get_day|date_get_hour|date_get_minute|date_get_second|date_get_weekday|date_get_day_of_year|date_get_hour_of_year|date_get_minute_of_year|date_get_second_of_year|date_year_span|date_month_span|date_week_span|date_day_span|date_hour_span|date_minute_span|date_second_span|date_compare_datetime|date_compare_date|date_compare_time|date_date_of|date_time_of|date_datetime_string|date_date_string|date_time_string|date_days_in_month|date_days_in_year|date_leap_year|date_is_today|date_set_timezone|date_get_timezone|motion_set|motion_add|place_free|place_empty|place_meeting|place_snapped|move_random|move_snap|move_towards_point|move_contact_solid|move_contact_all|move_outside_solid|move_outside_all|move_bounce_solid|move_bounce_all|move_wrap|distance_to_point|distance_to_object|position_empty|position_meeting|path_start|path_end|mp_linear_step|mp_potential_step|mp_linear_step_object|mp_potential_step_object|mp_potential_settings|mp_linear_path|mp_potential_path|mp_linear_path_object|mp_potential_path_object|mp_grid_create|mp_grid_destroy|mp_grid_clear_all|mp_grid_clear_cell|mp_grid_clear_rectangle|mp_grid_add_cell|mp_grid_get_cell|mp_grid_add_rectangle|mp_grid_add_instances|mp_grid_path|mp_grid_draw|mp_grid_to_ds_grid|collision_point|collision_rectangle|collision_circle|collision_ellipse|collision_line|point_in_rectangle|point_in_triangle|point_in_circle|rectangle_in_rectangle|rectangle_in_triangle|rectangle_in_circle|instance_find|instance_exists|instance_number|instance_position|instance_nearest|instance_furthest|instance_place|instance_create|instance_copy|instance_change|instance_destroy|position_destroy|position_change|instance_deactivate_all|instance_deactivate_object|instance_deactivate_region|instance_activate_all|instance_activate_object|instance_activate_region|room_goto|room_goto_previous|room_goto_next|room_previous|room_next|room_restart|game_end|game_restart|game_load|game_save|game_save_buffer|game_load_buffer|event_perform|event_user|event_perform_object|event_inherited|show_debug_message|show_debug_overlay|keyboard_set_map|keyboard_get_map|keyboard_unset_map|keyboard_check|keyboard_check_pressed|keyboard_check_released|keyboard_check_direct|keyboard_get_numlock|keyboard_set_numlock|keyboard_key_press|keyboard_key_release|keyboard_clear|io_clear|browser_input_capture|mouse_check_button|mouse_check_button_pressed|mouse_check_button_released|mouse_wheel_up|mouse_wheel_down|mouse_clear|joystick_exists|joystick_direction|joystick_name|joystick_axes|joystick_buttons|joystick_has_pov|joystick_check_button|joystick_xpos|joystick_ypos|joystick_zpos|joystick_rpos|joystick_upos|joystick_vpos|joystick_pov|draw_self|draw_sprite|draw_sprite_pos|draw_sprite_ext|draw_sprite_stretched|draw_sprite_stretched_ext|draw_sprite_tiled|draw_sprite_tiled_ext|draw_sprite_part|draw_sprite_part_ext|draw_sprite_general|draw_background|draw_background_ext|draw_background_stretched|draw_background_stretched_ext|draw_background_tiled|draw_background_tiled_ext|draw_background_part|draw_background_part_ext|draw_background_general|draw_clear|draw_clear_alpha|draw_point|draw_line|draw_line_width|draw_rectangle|draw_roundrect|draw_roundrect_ext|draw_triangle|draw_circle|draw_ellipse|draw_set_circle_precision|draw_arrow|draw_button|draw_path|draw_healthbar|draw_getpixel|draw_getpixel_ext|draw_set_colour|draw_set_alpha|draw_get_colour|draw_get_alpha|make_colour_rgb|make_colour_hsv|colour_get_red|colour_get_green|colour_get_blue|colour_get_hue|colour_get_saturation|colour_get_value|merge_colour|screen_save|screen_save_part|draw_set_font|draw_set_halign|draw_set_valign|draw_text|draw_text_ext|string_width|string_height|string_width_ext|string_height_ext|draw_text_transformed|draw_text_ext_transformed|draw_text_colour|draw_text_ext_colour|draw_text_transformed_colour|draw_text_ext_transformed_colour|draw_point_colour|draw_line_colour|draw_line_width_colour|draw_rectangle_colour|draw_roundrect_colour|draw_roundrect_colour_ext|draw_triangle_colour|draw_circle_colour|draw_ellipse_colour|draw_primitive_begin|draw_vertex|draw_vertex_colour|draw_primitive_end|sprite_get_uvs|background_get_uvs|font_get_uvs|sprite_get_texture|background_get_texture|font_get_texture|texture_get_width|texture_get_height|draw_primitive_begin_texture|draw_vertex_texture|draw_vertex_texture_colour|texture_set_interpolation|texture_set_interpolation_ext|texture_set_blending|texture_set_repeat|texture_set_repeat_ext|draw_set_blend_mode|draw_set_blend_mode_ext|draw_set_colour_write_enable|draw_set_alpha_test|draw_set_alpha_test_ref_value|draw_get_alpha_test|draw_get_alpha_test_ref_value|surface_create|surface_create_ext|surface_resize|surface_free|surface_exists|surface_get_width|surface_get_height|surface_get_texture|surface_set_target|surface_set_target_ext|surface_reset_target|draw_surface|draw_surface_stretched|draw_surface_tiled|draw_surface_part|draw_surface_ext|draw_surface_stretched_ext|draw_surface_tiled_ext|draw_surface_part_ext|draw_surface_general|surface_getpixel|surface_getpixel_ext|surface_save|surface_save_part|surface_copy|surface_copy_part|application_surface_draw_enable|application_get_position|application_surface_enable|application_surface_is_enabled|tile_add|tile_get_count|tile_get_id|tile_get_ids|tile_get_ids_at_depth|tile_delete|tile_exists|tile_get_x|tile_get_y|tile_get_left|tile_get_top|tile_get_width|tile_get_height|tile_get_depth|tile_get_visible|tile_get_xscale|tile_get_yscale|tile_get_background|tile_get_blend|tile_get_alpha|tile_set_position|tile_set_region|tile_set_background|tile_set_visible|tile_set_depth|tile_set_scale|tile_set_blend|tile_set_alpha|tile_layer_hide|tile_layer_show|tile_layer_delete|tile_layer_shift|tile_layer_find|tile_layer_delete_at|tile_layer_depth|display_get_width|display_get_height|display_get_orientation|display_get_gui_width|display_get_gui_height|display_reset|display_mouse_get_x|display_mouse_get_y|display_mouse_set|window_set_fullscreen|window_get_fullscreen|window_set_caption|window_set_min_width|window_set_max_width|window_set_min_height|window_set_max_height|window_get_visible_rects|window_get_caption|window_set_cursor|window_get_cursor|window_set_colour|window_get_colour|window_set_position|window_set_size|window_set_rectangle|window_center|window_get_x|window_get_y|window_get_width|window_get_height|window_mouse_get_x|window_mouse_get_y|window_mouse_set|window_view_mouse_get_x|window_view_mouse_get_y|window_views_mouse_get_x|window_views_mouse_get_y|sound_play|sound_loop|sound_stop|sound_stop_all|sound_isplaying|sound_volume|sound_global_volume|sound_fade|audio_listener_position|audio_listener_velocity|audio_listener_orientation|audio_emitter_position|audio_emitter_create|audio_emitter_free|audio_emitter_exists|audio_emitter_pitch|audio_emitter_velocity|audio_emitter_falloff|audio_emitter_gain|audio_play_sound|audio_play_sound_on|audio_play_sound_at|audio_stop_sound|audio_resume_sound|audio_pause_sound|audio_channel_num|audio_sound_length|audio_get_type|audio_falloff_set_model|audio_master_gain|audio_sound_gain|audio_sound_pitch|audio_stop_all|audio_resume_all|audio_pause_all|audio_is_playing|audio_is_paused|audio_exists|audio_emitter_get_gain|audio_emitter_get_pitch|audio_emitter_get_x|audio_emitter_get_y|audio_emitter_get_z|audio_emitter_get_vx|audio_emitter_get_vy|audio_emitter_get_vz|audio_listener_set_position|audio_listener_set_velocity|audio_listener_set_orientation|audio_listener_get_data|audio_set_master_gain|audio_get_master_gain|audio_sound_get_gain|audio_sound_get_pitch|audio_get_name|audio_sound_set_track_position|audio_sound_get_track_position|audio_create_stream|audio_destroy_stream|audio_create_sync_group|audio_play_in_sync_group|audio_start_sync_group|audio_stop_sync_group|audio_pause_sync_group|audio_resume_sync_group|audio_sync_group_get_track_pos|audio_sync_group_debug|audio_sync_group_is_playing|audio_debug|audio_group_load|audio_group_unload|audio_group_is_loaded|audio_group_load_progress|audio_group_name|audio_group_stop_all|audio_group_set_gain|audio_create_buffer_sound|audio_free_buffer_sound|audio_create_play_queue|audio_free_play_queue|audio_queue_sound|audio_get_recorder_count|audio_get_recorder_info|audio_start_recording|audio_stop_recording|audio_sound_get_listener_mask|audio_emitter_get_listener_mask|audio_get_listener_mask|audio_sound_set_listener_mask|audio_emitter_set_listener_mask|audio_set_listener_mask|audio_get_listener_count|audio_get_listener_info|audio_system|show_message|show_message_async|clickable_add|clickable_add_ext|clickable_change|clickable_change_ext|clickable_delete|clickable_exists|clickable_set_style|show_question|show_question_async|get_integer|get_string|get_integer_async|get_string_async|get_login_async|message_caption|get_open_filename|get_save_filename|get_open_filename_ext|get_save_filename_ext|show_error|highscore_clear|highscore_add|highscore_value|highscore_name|draw_highscore|sprite_exists|sprite_get_name|sprite_get_number|sprite_get_width|sprite_get_height|sprite_get_xoffset|sprite_get_yoffset|sprite_get_bbox_left|sprite_get_bbox_right|sprite_get_bbox_top|sprite_get_bbox_bottom|sprite_save|sprite_save_strip|sprite_set_cache_size|sprite_set_cache_size_ext|sprite_get_tpe|sound_exists|sound_get_name|sound_get_kind|sound_get_preload|sound_discard|sound_restore|background_exists|background_get_name|background_get_width|background_get_height|background_save|font_exists|font_get_name|font_get_fontname|font_get_bold|font_get_italic|font_get_first|font_get_last|font_get_size|font_set_cache_size|path_exists|path_get_name|path_get_length|path_get_kind|path_get_closed|path_get_precision|path_get_number|path_get_point_x|path_get_point_y|path_get_point_speed|path_get_x|path_get_y|path_get_speed|script_exists|script_get_name|timeline_exists|timeline_get_name|timeline_moment_clear|timeline_moment_add_script|timeline_size|timeline_max_moment|object_exists|object_get_name|object_get_sprite|object_get_solid|object_get_visible|object_get_depth|object_get_persistent|object_get_mask|object_get_parent|object_get_physics|object_is_ancestor|room_exists|room_get_name|sprite_set_offset|sprite_duplicate|sprite_assign|sprite_merge|sprite_add|sprite_replace|sprite_create_from_surface|sprite_add_from_surface|sprite_delete|sprite_set_alpha_from_sprite|sprite_collision_mask|sound_delete|background_duplicate|background_assign|background_add|background_replace|background_create_colour|background_create_gradient|background_create_from_surface|background_delete|background_set_alpha_from_background|font_add|font_add_sprite|font_add_sprite_ext|font_replace|font_replace_sprite|font_replace_sprite_ext|font_delete|path_set_kind|path_set_closed|path_set_precision|path_add|path_assign|path_duplicate|path_append|path_delete|path_add_point|path_insert_point|path_change_point|path_delete_point|path_clear_points|path_reverse|path_mirror|path_flip|path_rotate|path_rescale|path_shift|script_execute|timeline_add|timeline_delete|timeline_clear|object_set_sprite|object_set_solid|object_set_visible|object_set_depth|object_set_persistent|object_set_mask|room_set_width|room_set_height|room_set_persistent|room_set_background_colour|room_set_background|room_set_view|room_set_view_enabled|room_add|room_duplicate|room_assign|room_instance_add|room_instance_clear|room_tile_add|room_tile_add_ext|room_tile_clear|asset_get_index|asset_get_type|file_text_open_from_string|file_text_open_read|file_text_open_write|file_text_open_append|file_text_close|file_text_write_string|file_text_write_real|file_text_writeln|file_text_read_string|file_text_read_real|file_text_readln|file_text_eof|file_text_eoln|file_exists|file_delete|file_rename|file_copy|directory_exists|directory_create|directory_destroy|file_find_first|file_find_next|file_find_close|file_attributes|filename_name|filename_path|filename_dir|filename_drive|filename_ext|filename_change_ext|file_bin_open|file_bin_rewrite|file_bin_close|file_bin_position|file_bin_size|file_bin_seek|file_bin_write_byte|file_bin_read_byte|parameter_count|parameter_string|environment_get_variable|ini_open_from_string|ini_open|ini_close|ini_read_string|ini_read_real|ini_write_string|ini_write_real|ini_key_exists|ini_section_exists|ini_key_delete|ini_section_delete|ds_set_precision|ds_exists|ds_stack_create|ds_stack_destroy|ds_stack_clear|ds_stack_copy|ds_stack_size|ds_stack_empty|ds_stack_push|ds_stack_pop|ds_stack_top|ds_stack_write|ds_stack_read|ds_queue_create|ds_queue_destroy|ds_queue_clear|ds_queue_copy|ds_queue_size|ds_queue_empty|ds_queue_enqueue|ds_queue_dequeue|ds_queue_head|ds_queue_tail|ds_queue_write|ds_queue_read|ds_list_create|ds_list_destroy|ds_list_clear|ds_list_copy|ds_list_size|ds_list_empty|ds_list_add|ds_list_insert|ds_list_replace|ds_list_delete|ds_list_find_index|ds_list_find_value|ds_list_mark_as_list|ds_list_mark_as_map|ds_list_sort|ds_list_shuffle|ds_list_write|ds_list_read|ds_map_create|ds_map_destroy|ds_map_clear|ds_map_copy|ds_map_size|ds_map_empty|ds_map_add|ds_map_add_list|ds_map_add_map|ds_map_replace|ds_map_replace_map|ds_map_replace_list|ds_map_delete|ds_map_exists|ds_map_find_value|ds_map_find_previous|ds_map_find_next|ds_map_find_first|ds_map_find_last|ds_map_write|ds_map_read|ds_map_secure_save|ds_map_secure_load|ds_priority_create|ds_priority_destroy|ds_priority_clear|ds_priority_copy|ds_priority_size|ds_priority_empty|ds_priority_add|ds_priority_change_priority|ds_priority_find_priority|ds_priority_delete_value|ds_priority_delete_min|ds_priority_find_min|ds_priority_delete_max|ds_priority_find_max|ds_priority_write|ds_priority_read|ds_grid_create|ds_grid_destroy|ds_grid_copy|ds_grid_resize|ds_grid_width|ds_grid_height|ds_grid_clear|ds_grid_set|ds_grid_add|ds_grid_multiply|ds_grid_set_region|ds_grid_add_region|ds_grid_multiply_region|ds_grid_set_disk|ds_grid_add_disk|ds_grid_multiply_disk|ds_grid_set_grid_region|ds_grid_add_grid_region|ds_grid_multiply_grid_region|ds_grid_get|ds_grid_get_sum|ds_grid_get_max|ds_grid_get_min|ds_grid_get_mean|ds_grid_get_disk_sum|ds_grid_get_disk_min|ds_grid_get_disk_max|ds_grid_get_disk_mean|ds_grid_value_exists|ds_grid_value_x|ds_grid_value_y|ds_grid_value_disk_exists|ds_grid_value_disk_x|ds_grid_value_disk_y|ds_grid_shuffle|ds_grid_write|ds_grid_read|ds_grid_sort|effect_create_below|effect_create_above|effect_clear|part_type_create|part_type_destroy|part_type_exists|part_type_clear|part_type_shape|part_type_sprite|part_type_size|part_type_scale|part_type_orientation|part_type_life|part_type_step|part_type_death|part_type_speed|part_type_direction|part_type_gravity|part_type_colour1|part_type_colour2|part_type_colour3|part_type_colour_mix|part_type_colour_rgb|part_type_colour_hsv|part_type_alpha1|part_type_alpha2|part_type_alpha3|part_type_blend|part_system_create|part_system_destroy|part_system_exists|part_system_clear|part_system_draw_order|part_system_depth|part_system_position|part_system_automatic_update|part_system_automatic_draw|part_system_update|part_system_drawit|part_particles_create|part_particles_create_colour|part_particles_clear|part_particles_count|part_emitter_create|part_emitter_destroy|part_emitter_destroy_all|part_emitter_exists|part_emitter_clear|part_emitter_region|part_emitter_burst|part_emitter_stream|external_call|external_define|external_free|window_handle|window_device|d3d_start|d3d_end|d3d_set_hidden|d3d_set_perspective|d3d_set_depth|d3d_primitive_begin|d3d_vertex|d3d_vertex_colour|d3d_primitive_end|d3d_primitive_begin_texture|d3d_vertex_texture|d3d_vertex_texture_colour|d3d_draw_block|d3d_draw_cylinder|d3d_draw_cone|d3d_draw_ellipsoid|d3d_draw_wall|d3d_draw_floor|d3d_set_projection|d3d_set_projection_ext|d3d_set_projection_ortho|d3d_set_projection_perspective|d3d_transform_set_identity|d3d_transform_set_translation|d3d_transform_set_scaling|d3d_transform_set_rotation_x|d3d_transform_set_rotation_y|d3d_transform_set_rotation_z|d3d_transform_set_rotation_axis|d3d_transform_add_translation|d3d_transform_add_scaling|d3d_transform_add_rotation_x|d3d_transform_add_rotation_y|d3d_transform_add_rotation_z|d3d_transform_add_rotation_axis|d3d_transform_stack_clear|d3d_transform_stack_empty|d3d_transform_stack_push|d3d_transform_stack_pop|d3d_transform_stack_top|d3d_transform_stack_discard|d3d_transform_vertex|d3d_set_fog|d3d_set_lighting|d3d_set_shading|d3d_set_culling|d3d_set_zwriteenable|d3d_light_define_ambient|d3d_light_define_direction|d3d_light_define_point|d3d_light_enable|d3d_vertex_normal|d3d_vertex_normal_colour|d3d_vertex_normal_texture|d3d_vertex_normal_texture_colour|d3d_model_create|d3d_model_destroy|d3d_model_clear|d3d_model_save|d3d_model_load|d3d_model_draw|d3d_model_primitive_begin|d3d_model_vertex|d3d_model_vertex_colour|d3d_model_vertex_texture|d3d_model_vertex_texture_colour|d3d_model_vertex_normal|d3d_model_vertex_normal_colour|d3d_model_vertex_normal_texture|d3d_model_vertex_normal_texture_colour|d3d_model_primitive_end|d3d_model_block|d3d_model_cylinder|d3d_model_cone|d3d_model_ellipsoid|d3d_model_wall|d3d_model_floor|matrix_get|matrix_set|matrix_build|matrix_multiply|os_get_config|os_get_info|os_get_language|os_get_region|os_lock_orientation|display_get_dpi_x|display_get_dpi_y|display_set_gui_size|display_set_gui_maximise|device_mouse_dbclick_enable|virtual_key_add|virtual_key_hide|virtual_key_delete|virtual_key_show|draw_enable_alphablend|draw_enable_drawevent|draw_enable_swf_aa|draw_set_swf_aa_level|draw_get_swf_aa_level|draw_texture_flush|shop_leave_rating|url_get_domain|url_open|url_open_ext|url_open_full|get_timer|achievement_login|achievement_logout|achievement_post|achievement_increment|achievement_post_score|achievement_available|achievement_show_achievements|achievement_show_leaderboards|achievement_load_friends|achievement_load_leaderboard|achievement_send_challenge|achievement_load_progress|achievement_reset|achievement_login_status|achievement_get_pic|achievement_show_challenge_notifications|achievement_get_challenges|achievement_event|achievement_show|achievement_get_info|cloud_file_save|cloud_string_save|cloud_synchronise|ads_enable|ads_disable|ads_setup|ads_engagement_launch|ads_engagement_available|ads_engagement_active|ads_event|ads_event_preload|ads_set_reward_callback|playhaven_add_notification_badge|playhaven_hide_notification_badge|playhaven_update_notification_badge|playhaven_position_notification_badge|ads_get_display_height|ads_get_display_width|ads_move|ads_interstitial_available|ads_interstitial_display|pocketchange_display_reward|pocketchange_display_shop|device_get_tilt_x|device_get_tilt_y|device_get_tilt_z|device_is_keypad_open|device_ios_get_imagename|device_ios_get_image|openfeint_start|openfeint_send_challenge|openfeint_send_invite|openfeint_send_social|openfeint_set_url|openfeint_accept_challenge|openfeint_send_result|device_mouse_check_button|device_mouse_check_button_pressed|device_mouse_check_button_released|device_mouse_x|device_mouse_y|device_mouse_raw_x|device_mouse_raw_y|device_mouse_x_to_gui|device_mouse_y_to_gui|iap_activate|iap_status|iap_enumerate_products|iap_restore_all|iap_acquire|iap_consume|iap_product_details|iap_purchase_details|iap_is_purchased|facebook_init|facebook_login|facebook_status|facebook_graph_request|facebook_dialog|facebook_logout|facebook_launch_offerwall|facebook_post_message|facebook_send_invite|facebook_user_id|facebook_accesstoken|facebook_check_permission|facebook_request_read_permissions|facebook_request_publish_permissions|gamepad_is_supported|gamepad_get_device_count|gamepad_is_connected|gamepad_get_description|gamepad_get_button_threshold|gamepad_set_button_threshold|gamepad_get_axis_deadzone|gamepad_set_axis_deadzone|gamepad_button_count|gamepad_button_check|gamepad_button_check_pressed|gamepad_button_check_released|gamepad_button_value|gamepad_axis_count|gamepad_axis_value|gamepad_set_vibration|gamepad_set_color|gamepad_set_colour|os_is_paused|window_has_focus|code_is_compiled|http_get|http_get_file|http_post_string|http_request|json_encode|json_decode|zip_unzip|base64_encode|base64_decode|md5_string_unicode|md5_string_utf8|md5_file|os_is_network_connected|sha1_string_unicode|sha1_string_utf8|sha1_file|os_powersave_enable|analytics_event|analytics_event_ext|win8_livetile_tile_notification|win8_livetile_tile_clear|win8_livetile_badge_notification|win8_livetile_badge_clear|win8_livetile_queue_enable|win8_secondarytile_pin|win8_secondarytile_badge_notification|win8_secondarytile_delete|win8_livetile_notification_begin|win8_livetile_notification_secondary_begin|win8_livetile_notification_expiry|win8_livetile_notification_tag|win8_livetile_notification_text_add|win8_livetile_notification_image_add|win8_livetile_notification_end|win8_appbar_enable|win8_appbar_add_element|win8_appbar_remove_element|win8_settingscharm_add_entry|win8_settingscharm_add_html_entry|win8_settingscharm_add_xaml_entry|win8_settingscharm_set_xaml_property|win8_settingscharm_get_xaml_property|win8_settingscharm_remove_entry|win8_share_image|win8_share_screenshot|win8_share_file|win8_share_url|win8_share_text|win8_search_enable|win8_search_disable|win8_search_add_suggestions|win8_device_touchscreen_available|win8_license_initialize_sandbox|win8_license_trial_version|winphone_license_trial_version|winphone_tile_title|winphone_tile_count|winphone_tile_back_title|winphone_tile_back_content|winphone_tile_back_content_wide|winphone_tile_front_image|winphone_tile_front_image_small|winphone_tile_front_image_wide|winphone_tile_back_image|winphone_tile_back_image_wide|winphone_tile_background_colour|winphone_tile_icon_image|winphone_tile_small_icon_image|winphone_tile_wide_content|winphone_tile_cycle_images|winphone_tile_small_background_image|physics_world_create|physics_world_gravity|physics_world_update_speed|physics_world_update_iterations|physics_world_draw_debug|physics_pause_enable|physics_fixture_create|physics_fixture_set_kinematic|physics_fixture_set_density|physics_fixture_set_awake|physics_fixture_set_restitution|physics_fixture_set_friction|physics_fixture_set_collision_group|physics_fixture_set_sensor|physics_fixture_set_linear_damping|physics_fixture_set_angular_damping|physics_fixture_set_circle_shape|physics_fixture_set_box_shape|physics_fixture_set_edge_shape|physics_fixture_set_polygon_shape|physics_fixture_set_chain_shape|physics_fixture_add_point|physics_fixture_bind|physics_fixture_bind_ext|physics_fixture_delete|physics_apply_force|physics_apply_impulse|physics_apply_angular_impulse|physics_apply_local_force|physics_apply_local_impulse|physics_apply_torque|physics_mass_properties|physics_draw_debug|physics_test_overlap|physics_remove_fixture|physics_set_friction|physics_set_density|physics_set_restitution|physics_get_friction|physics_get_density|physics_get_restitution|physics_joint_distance_create|physics_joint_rope_create|physics_joint_revolute_create|physics_joint_prismatic_create|physics_joint_pulley_create|physics_joint_wheel_create|physics_joint_weld_create|physics_joint_friction_create|physics_joint_gear_create|physics_joint_enable_motor|physics_joint_get_value|physics_joint_set_value|physics_joint_delete|physics_particle_create|physics_particle_delete|physics_particle_delete_region_circle|physics_particle_delete_region_box|physics_particle_delete_region_poly|physics_particle_set_flags|physics_particle_set_category_flags|physics_particle_draw|physics_particle_draw_ext|physics_particle_count|physics_particle_get_data|physics_particle_get_data_particle|physics_particle_group_begin|physics_particle_group_circle|physics_particle_group_box|physics_particle_group_polygon|physics_particle_group_add_point|physics_particle_group_end|physics_particle_group_join|physics_particle_group_delete|physics_particle_group_count|physics_particle_group_get_data|physics_particle_group_get_mass|physics_particle_group_get_inertia|physics_particle_group_get_centre_x|physics_particle_group_get_centre_y|physics_particle_group_get_vel_x|physics_particle_group_get_vel_y|physics_particle_group_get_ang_vel|physics_particle_group_get_x|physics_particle_group_get_y|physics_particle_group_get_angle|physics_particle_set_group_flags|physics_particle_get_group_flags|physics_particle_get_max_count|physics_particle_get_radius|physics_particle_get_density|physics_particle_get_damping|physics_particle_get_gravity_scale|physics_particle_set_max_count|physics_particle_set_radius|physics_particle_set_density|physics_particle_set_damping|physics_particle_set_gravity_scale|network_create_socket|network_create_server|network_create_server_raw|network_connect|network_connect_raw|network_send_packet|network_send_raw|network_send_broadcast|network_send_udp|network_send_udp_raw|network_set_timeout|network_resolve|network_destroy|buffer_create|buffer_write|buffer_read|buffer_seek|buffer_get_surface|buffer_set_surface|buffer_delete|buffer_poke|buffer_peek|buffer_save|buffer_save_ext|buffer_load|buffer_load_ext|buffer_load_partial|buffer_copy|buffer_fill|buffer_get_size|buffer_tell|buffer_resize|buffer_md5|buffer_sha1|buffer_base64_encode|buffer_base64_decode|buffer_base64_decode_ext|buffer_sizeof|buffer_get_address|buffer_create_from_vertex_buffer|buffer_create_from_vertex_buffer_ext|buffer_copy_from_vertex_buffer|buffer_async_group_begin|buffer_async_group_option|buffer_load_async|buffer_save_async|immersion_play_effect|immersion_stop|gml_release_mode|steam_activate_overlay|steam_is_overlay_enabled|steam_is_overlay_activated|steam_get_persona_name|steam_initialised|steam_is_cloud_enabled_for_app|steam_is_cloud_enabled_for_account|steam_file_persisted|steam_get_quota_total|steam_get_quota_free|steam_file_write|steam_file_write_file|steam_file_read|steam_file_delete|steam_file_exists|steam_file_size|steam_file_share|steam_publish_workshop_file|steam_is_screenshot_requested|steam_send_screenshot|steam_is_user_logged_on|steam_get_user_steam_id|steam_user_owns_dlc|steam_user_installed_dlc|steam_set_achievement|steam_get_achievement|steam_clear_achievement|steam_set_stat_int|steam_set_stat_float|steam_set_stat_avg_rate|steam_get_stat_int|steam_get_stat_float|steam_get_stat_avg_rate|steam_reset_all_stats|steam_reset_all_stats_achievements|steam_stats_ready|steam_create_leaderboard|steam_upload_score|steam_download_scores_around_user|steam_download_scores|steam_download_friends_scores|steam_upload_score_buffer|steam_get_app_id|steam_get_user_account_id|steam_ugc_download|steam_ugc_create_item|steam_ugc_start_item_update|steam_ugc_set_item_title|steam_ugc_set_item_description|steam_ugc_set_item_visibility|steam_ugc_set_item_tags|steam_ugc_set_item_content|steam_ugc_set_item_preview|steam_ugc_submit_item_update|steam_ugc_get_item_update_progress|steam_ugc_subscribe_item|steam_ugc_unsubscribe_item|steam_ugc_num_subscribed_items|steam_ugc_get_subscribed_items|steam_ugc_get_item_install_info|steam_ugc_get_item_update_info|steam_ugc_request_item_details|steam_ugc_create_query_user|steam_ugc_create_query_user_ex|steam_ugc_create_query_all|steam_ugc_create_query_all_ex|steam_ugc_query_set_cloud_filename_filter|steam_ugc_query_set_match_any_tag|steam_ugc_query_set_search_text|steam_ugc_query_set_ranked_by_trend_days|steam_ugc_query_add_required_tag|steam_ugc_query_add_excluded_tag|steam_ugc_query_set_return_long_description|steam_ugc_query_set_return_total_only|steam_ugc_query_set_allow_cached_response|steam_ugc_send_query|shader_set|shader_reset|shader_is_compiled|shader_get_sampler_index|shader_get_uniform|shader_set_uniform_i|shader_set_uniform_i_array|shader_set_uniform_f|shader_set_uniform_f_array|shader_set_uniform_matrix|shader_set_uniform_matrix_array|shader_enable_corner_id|texture_set_stage|texture_get_texel_width|texture_get_texel_height|shaders_are_supported|vertex_format_begin|vertex_format_end|vertex_format_add_position|vertex_format_add_position_3d|vertex_format_add_colour|vertex_format_add_normal|vertex_format_add_textcoord|vertex_format_add_custom|vertex_create_buffer|vertex_create_buffer_ext|vertex_delete_buffer|vertex_begin|vertex_end|vertex_position|vertex_position_3d|vertex_colour|vertex_argb|vertex_texcoord|vertex_normal|vertex_float1|vertex_float2|vertex_float3|vertex_float4|vertex_ubyte4|vertex_submit|vertex_freeze|vertex_get_number|vertex_get_buffer_size|vertex_create_buffer_from_buffer|vertex_create_buffer_from_buffer_ext|push_local_notification|push_get_first_local_notification|push_get_next_local_notification|push_cancel_local_notification|skeleton_animation_set|skeleton_animation_get|skeleton_animation_mix|skeleton_animation_set_ext|skeleton_animation_get_ext|skeleton_animation_get_duration|skeleton_animation_clear|skeleton_skin_set|skeleton_skin_get|skeleton_attachment_set|skeleton_attachment_get|skeleton_attachment_create|skeleton_collision_draw_set|skeleton_bone_data_get|skeleton_bone_data_set|skeleton_bone_state_get|skeleton_bone_state_set|draw_skeleton|draw_skeleton_time|draw_skeleton_collision|skeleton_animation_list|skeleton_skin_list|skeleton_slot_data)\b", RegexCompiledOption); | |
GMLKeywordRegex = new Regex(@"\b(if|then|else|and|or|while|do|for|switch|case|until|div|mod|repeat|break|continue|exit|return|var|globalvar|with)\b", RegexCompiledOption); | |
GMLReadOnlyRegex = new Regex(@"\b(argument_relative|path_index|object_index|id|instance_count|instance_id|fps|fps_real|current_time|current_year|current_month|current_day|current_weekday|current_hour|current_minute|current_second|room_first|room_last|room_width|room_height|event_type|event_number|event_object|event_action|application_surface|debug_mode|mouse_x|mouse_y|sprite_width|sprite_height|sprite_xoffset|sprite_yoffset|image_number|bbox_left|bbox_right|bbox_top|bbox_bottom|view_current|game_id|game_display_name|game_project_name|game_save_id|working_directory|temp_directory|program_directory|browser_width|browser_height|os_type|os_device|os_browser|os_version|display_aa|async_load|delta_time|webgl_enabled|iap_data|phy_speed|phy_mass|phy_inertia|phy_com_x|phy_com_y|phy_dynamic|phy_kinematic|phy_sleeping|phy_collision_points|phy_collision_x|phy_collision_y|phy_col_normal_x|phy_col_normal_y|phy_position_xprevious|phy_position_yprevious)\b", RegexCompiledOption); | |
} | |
public virtual void GMLSynaxHighlight(Range range) { | |
if (GMLKeywordRegex == null) { | |
InitGMLRegex(); | |
} | |
//this.JScriptSyntaxHighlight(range); | |
range.tb.LeftBracket = '('; | |
range.tb.RightBracket = ')'; | |
range.ClearStyle(StringStyle, CommentStyle, NumberStyle, KeywordStyle, KeywordStyle2); | |
range.SetStyle(KeywordStyle, GMLKeywordRegex); | |
range.SetStyle(KeywordStyle2, GMLReadOnlyRegex); | |
range.SetStyle(KeywordStyle3, GMLFunctionsRegex); | |
range.SetStyle(NumberStyle, GMLNumberRegex); | |
range.SetFoldingMarkers("{", "}");//allow to collapse brackets block | |
range.SetFoldingMarkers(@"/\*", @"\*/");//allow to collapse comment block | |
} | |
public void Dispose() | |
{ | |
foreach (var desc in descByXMLfileNames.Values) | |
desc.Dispose(); | |
} | |
} | |
/// <summary> | |
/// Language | |
/// </summary> | |
public enum Language | |
{ | |
Custom, CSharp, VB, HTML, SQL, PHP, JS, GML | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment