-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighlightersRules.cs
53 lines (49 loc) · 2.43 KB
/
HighlightersRules.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Text.RegularExpressions;
namespace SyntaxHighlighterCS
{
enum HighlighterOptions
{
JSON, XML, SQL, Cpp
}
internal class HighlighterRules : HighlighterBase
{
private HighlighterOptions option;
public HighlighterRules(RichTextBox richTextBox) : base(richTextBox, Color.White) { }
public void SelectOption(HighlighterOptions select)
{
option = select;
}
protected override void Highlight()
{
switch (option)
{
case HighlighterOptions.JSON:
HighlightPattern(@"\b(true|false|null)\b", Color.DeepSkyBlue);
HighlightPattern(@"""(.*)""\s*:", Color.LightGreen);
HighlightPattern(@":\s*"".*""", Color.LightSalmon);
HighlightPattern(@":", Color.LightYellow);
break;
case HighlighterOptions.XML:
HighlightPattern(@"<[!?]?[^<>]+?[!?]?>", Color.DeepSkyBlue);
HighlightPattern(@"(?<=\s)\w+=(?=""|')", Color.LightYellow);
HighlightPattern(@"""[^""]*""", Color.LightSalmon);
HighlightPattern(@"<!--.*?-->", Color.Gray, RegexOptions.Singleline, FontStyle.Italic);
break;
case HighlighterOptions.SQL:
HighlightPattern(@"\b(SELECT|UPDATE|DELETE|INSERT|FROM|WHERE|AND|OR|NOT|IN|AS|LIKE)\b",
Color.DeepSkyBlue, RegexOptions.IgnoreCase, FontStyle.Bold);
HighlightPattern(@"'[^']*'", Color.OrangeRed);
HighlightPattern(@"--.*$", Color.Green, RegexOptions.Multiline, FontStyle.Italic);
break;
case HighlighterOptions.Cpp:
HighlightPattern(@"\b(int|char|float|double|void|class|struct|if|else|while|for|return|break|continue|public|private|protected|static|const)\b",
Color.DeepSkyBlue, RegexOptions.None, FontStyle.Bold);
HighlightPattern(@"\""[^\""]*\""", Color.LightSalmon);
HighlightPattern(@"\#.*", Color.LightGray, RegexOptions.Multiline);
HighlightPattern(@"//.*$", Color.Green, RegexOptions.Multiline, FontStyle.Italic);
HighlightPattern(@"/\*.*?\*/", Color.Green, RegexOptions.Singleline, FontStyle.Italic);
break;
}
}
}
}