Skip to content

Commit c3da007

Browse files
committed
added comments support
1 parent 389536f commit c3da007

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

VMCompiler/Compiler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ internal static class Compiler
1616

1717
public static void Compile(string codeString, string filename)
1818
{
19+
{ //Clean codeString
20+
Regex comments = new Regex(" *\\/\\/.*");
21+
int deleted = 0;
22+
foreach(Match m in comments.Matches(codeString))
23+
{
24+
codeString = codeString.Remove(m.Index - deleted, m.Length);
25+
deleted += m.Length;
26+
}
27+
}
28+
1929
stringsContainer = new StringsContainer();
2030
globalVariables = new VariablesContainer();
2131
usingsContainer = new UsingContainer();

VMCompiler/Form1.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,21 @@ private void richTextBox1_TextChanged(object sender, EventArgs e)
5050
private void Highlight(string text, int offset)
5151
{
5252
Regex voids = new Regex("void ([a-zA-Z0-9]{1,})\\n{\\n(?:\\n*.*?\\n*){1,}}");
53-
MatchCollection voidsm = voids.Matches(text);
54-
foreach (Match match in voidsm)
53+
foreach (Match match in voids.Matches(text))
5554
{
5655
richTextBox1.Select(match.Index + offset, 4);
5756
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#3498db");
5857
}
5958

6059
Regex strings = new Regex("\"(.*?)\"");
61-
MatchCollection stringsm = strings.Matches(text);
62-
foreach (Match match in stringsm)
60+
foreach (Match match in strings.Matches(text))
6361
{
6462
richTextBox1.Select(match.Index + offset, match.Length);
6563
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#e67e22");
6664
}
6765

6866
Regex include = new Regex(@"using (.*?)=(.*?);");
69-
MatchCollection includem = include.Matches(text);
70-
foreach (Match match in includem)
67+
foreach (Match match in include.Matches(text))
7168
{
7269
richTextBox1.Select(match.Index + offset, 5);
7370
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#3498db");
@@ -80,57 +77,59 @@ private void Highlight(string text, int offset)
8077
}
8178

8279
Regex ints = new Regex(@" {1,}([0-9]{1,})\n*");
83-
MatchCollection intsm = ints.Matches(text);
84-
foreach (Match match in intsm)
80+
foreach (Match match in ints.Matches(text))
8581
{
8682
richTextBox1.Select(match.Groups[1].Index + offset, match.Groups[1].Length);
87-
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#27ae60");
83+
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#2ecc71");
8884
}
8985

9086
Regex calls = new Regex(@"Call ([a-zA-Z0-9]{1,})");
91-
MatchCollection callsm = calls.Matches(text);
92-
foreach (Match match in callsm)
87+
foreach (Match match in calls.Matches(text))
9388
{
9489
richTextBox1.Select(match.Groups[1].Index + offset, match.Groups[1].Length);
9590
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#3498db");
9691
}
9792

9893
Regex vars = new Regex(@"var ([a-zA-Z0-9]{1,})\n");
99-
MatchCollection varsm = vars.Matches(text);
100-
foreach (Match match in varsm)
94+
foreach (Match match in vars.Matches(text))
10195
{
10296
richTextBox1.Select(match.Index + offset, 3);
10397
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#3498db");
10498
}
10599

106100
Regex stldvar = new Regex(@"(?:Ld..|St..) (.*)\n");
107-
MatchCollection stldvarm = stldvar.Matches(text);
108-
foreach (Match match in stldvarm)
101+
foreach (Match match in stldvar.Matches(text))
109102
{
110103
richTextBox1.Select(match.Groups[1].Index, match.Groups[1].Length);
111104
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#3498db");
112105
}
113106

114107
Regex globaldef = new Regex(@"Global\n{");
115-
MatchCollection globaldefm = globaldef.Matches(text);
116-
foreach (Match match in globaldefm)
108+
foreach (Match match in globaldef.Matches(text))
117109
{
118110
richTextBox1.Select(match.Index + offset, 6);
119111
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#3498db");
120112
}
121113

114+
Regex comments = new Regex("\\/\\/.*");
115+
foreach (Match match in comments.Matches(text))
116+
{
117+
richTextBox1.Select(match.Index + offset, match.Length);
118+
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#95a5a6");
119+
}
120+
121+
122122
Regex callcsharp = new Regex(@"([a-zA-Z0-9]{1,})\:(.*?)\((.*)\)");
123-
MatchCollection callcsharpm = callcsharp.Matches(text);
124-
foreach (Match match in callcsharpm)
123+
foreach (Match match in callcsharp.Matches(text))
125124
{
126125
richTextBox1.Select(match.Groups[1].Index + offset, match.Groups[1].Length);
127-
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#27ae60");
126+
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#2ecc71");
128127

129128
richTextBox1.Select(match.Groups[2].Index + offset, match.Groups[2].Length);
130129
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#e67e22");
131130

132131
richTextBox1.Select(match.Groups[3].Index + offset, match.Groups[3].Length);
133-
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#27ae60");
132+
richTextBox1.SelectionColor = ColorTranslator.FromHtml("#2ecc71");
134133
}
135134
}
136135

0 commit comments

Comments
 (0)