forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilerOutputParserBase.cs
More file actions
161 lines (149 loc) · 4.96 KB
/
Copy pathCompilerOutputParserBase.cs
File metadata and controls
161 lines (149 loc) · 4.96 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace UnityEditor.Scripting.Compilers
{
internal abstract class CompilerOutputParserBase
{
protected static CompilerMessage CreateInternalCompilerErrorMessage(string[] compileroutput)
{
CompilerMessage result;
result.file = "";
result.message = string.Join("\n", compileroutput);
result.type = CompilerMessageType.Error;
result.line = 0;
result.column = 0;
result.normalizedStatus = default(NormalizedCompilerStatus);
return result;
}
protected internal static CompilerMessage CreateCompilerMessageFromMatchedRegex(string line, Match m, string erroridentifier)
{
CompilerMessage result;
result.file = m.Groups["filename"].Value;
result.message = line;
result.line = int.Parse(m.Groups["line"].Value);
result.column = int.Parse(m.Groups["column"].Value);
result.type = ((!(m.Groups["type"].Value == erroridentifier)) ? CompilerMessageType.Warning : CompilerMessageType.Error);
result.normalizedStatus = default(NormalizedCompilerStatus);
return result;
}
public virtual IEnumerable<CompilerMessage> Parse(string[] errorOutput, bool compilationHadFailure)
{
return this.Parse(errorOutput, new string[0], compilationHadFailure);
}
public virtual IEnumerable<CompilerMessage> Parse(string[] errorOutput, string[] standardOutput, bool compilationHadFailure)
{
bool flag = false;
List<CompilerMessage> list = new List<CompilerMessage>();
Regex outputRegex = this.GetOutputRegex();
Regex internalErrorOutputRegex = this.GetInternalErrorOutputRegex();
int i = 0;
while (i < errorOutput.Length)
{
string text = errorOutput[i];
string input = (text.Length <= 1000) ? text : text.Substring(0, 100);
Match match = outputRegex.Match(input);
if (match.Success)
{
goto IL_88;
}
if (internalErrorOutputRegex != null)
{
match = internalErrorOutputRegex.Match(input);
}
if (match.Success)
{
goto IL_88;
}
IL_BF:
i++;
continue;
IL_88:
CompilerMessage item = CompilerOutputParserBase.CreateCompilerMessageFromMatchedRegex(text, match, this.GetErrorIdentifier());
item.normalizedStatus = this.NormalizedStatusFor(match);
if (item.type == CompilerMessageType.Error)
{
flag = true;
}
list.Add(item);
goto IL_BF;
}
if (compilationHadFailure && !flag)
{
list.Add(CompilerOutputParserBase.CreateInternalCompilerErrorMessage(errorOutput));
}
return list;
}
protected virtual NormalizedCompilerStatus NormalizedStatusFor(Match match)
{
return default(NormalizedCompilerStatus);
}
protected abstract string GetErrorIdentifier();
protected abstract Regex GetOutputRegex();
protected virtual Regex GetInternalErrorOutputRegex()
{
return null;
}
protected static NormalizedCompilerStatus TryNormalizeCompilerStatus(Match match, string idToCheck, Regex messageParser, Func<Match, Regex, NormalizedCompilerStatus> normalizer)
{
string value = match.Groups["id"].Value;
NormalizedCompilerStatus normalizedCompilerStatus = default(NormalizedCompilerStatus);
NormalizedCompilerStatus result;
if (value != idToCheck)
{
result = normalizedCompilerStatus;
}
else
{
result = normalizer(match, messageParser);
}
return result;
}
protected static NormalizedCompilerStatus NormalizeMemberNotFoundError(Match outputMatch, Regex messageParser)
{
NormalizedCompilerStatus result;
result.code = NormalizedCompilerStatusCode.MemberNotFound;
Match match = messageParser.Match(outputMatch.Groups["message"].Value);
result.details = match.Groups["type_name"].Value + "%" + match.Groups["member_name"].Value;
return result;
}
protected static NormalizedCompilerStatus NormalizeSimpleUnknownTypeOfNamespaceError(Match outputMatch, Regex messageParser)
{
NormalizedCompilerStatus result;
result.code = NormalizedCompilerStatusCode.UnknownTypeOrNamespace;
Match match = messageParser.Match(outputMatch.Groups["message"].Value);
result.details = string.Concat(new string[]
{
"EntityName=",
match.Groups["type_name"].Value,
"\nScript=",
outputMatch.Groups["filename"].Value,
"\nLine=",
outputMatch.Groups["line"].Value,
"\nColumn=",
outputMatch.Groups["column"].Value
});
return result;
}
protected static NormalizedCompilerStatus NormalizeUnknownTypeMemberOfNamespaceError(Match outputMatch, Regex messageParser)
{
NormalizedCompilerStatus result;
result.code = NormalizedCompilerStatusCode.UnknownTypeOrNamespace;
Match match = messageParser.Match(outputMatch.Groups["message"].Value);
result.details = string.Concat(new string[]
{
"EntityName=",
match.Groups["namespace"].Value,
".",
match.Groups["type_name"].Value,
"\nScript=",
outputMatch.Groups["filename"].Value,
"\nLine=",
outputMatch.Groups["line"].Value,
"\nColumn=",
outputMatch.Groups["column"].Value
});
return result;
}
}
}