forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilerOutputParserBase.cs
More file actions
138 lines (113 loc) · 5.54 KB
/
Copy pathCompilerOutputParserBase.cs
File metadata and controls
138 lines (113 loc) · 5.54 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace UnityEditor.Scripting.Compilers
{
internal abstract class CompilerOutputParserBase
{
static protected CompilerMessage CreateInternalCompilerErrorMessage(string[] compileroutput)
{
CompilerMessage message;
message.file = "";
message.message = String.Join("\n", compileroutput);
message.type = CompilerMessageType.Error;
message.line = 0;
message.column = 0;
message.normalizedStatus = default(NormalizedCompilerStatus);
return message;
}
internal static protected CompilerMessage CreateCompilerMessageFromMatchedRegex(string line, Match m, string erroridentifier)
{
CompilerMessage message;
message.file = m.Groups["filename"].Value;
message.message = line;
message.line = Int32.Parse(m.Groups["line"].Value);
message.column = Int32.Parse(m.Groups["column"].Value);
message.type = (m.Groups["type"].Value == erroridentifier) ? CompilerMessageType.Error : CompilerMessageType.Warning;
message.normalizedStatus = default(NormalizedCompilerStatus);
return message;
}
public virtual IEnumerable<CompilerMessage> Parse(string[] errorOutput, bool compilationHadFailure)
{
return Parse(errorOutput, new string[0], compilationHadFailure);
}
public virtual IEnumerable<CompilerMessage> Parse(string[] errorOutput, string[] standardOutput, bool compilationHadFailure)
{
var hasErrors = false;
var msgs = new List<CompilerMessage>();
var regex = GetOutputRegex();
var internalErrorRegex = GetInternalErrorOutputRegex();
foreach (var line in errorOutput)
{
//Jamplus can fail with enormous lines in the stdout, parsing of which can take 30! seconds.
var line2 = line.Length > 1000 ? line.Substring(0, 100) : line;
Match m = regex.Match(line2);
if (!m.Success)
{
if (internalErrorRegex != null)
m = internalErrorRegex.Match(line2);
if (!m.Success)
continue;
}
CompilerMessage message = CreateCompilerMessageFromMatchedRegex(line, m, GetErrorIdentifier());
message.normalizedStatus = NormalizedStatusFor(m);
if (message.type == CompilerMessageType.Error)
hasErrors = true;
msgs.Add(message);
}
if (compilationHadFailure && !hasErrors)
{
msgs.Add(CreateInternalCompilerErrorMessage(errorOutput));
}
return msgs;
}
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)
{
var id = match.Groups["id"].Value;
var ret = default(NormalizedCompilerStatus);
if (id != idToCheck)
return ret;
return normalizer(match, messageParser);
}
protected static NormalizedCompilerStatus NormalizeMemberNotFoundError(Match outputMatch, Regex messageParser)
{
NormalizedCompilerStatus ret;
ret.code = NormalizedCompilerStatusCode.MemberNotFound;
var dm = messageParser.Match(outputMatch.Groups["message"].Value);
ret.details = dm.Groups["type_name"].Value + "%" + dm.Groups["member_name"].Value;
return ret;
}
protected static NormalizedCompilerStatus NormalizeSimpleUnknownTypeOfNamespaceError(Match outputMatch, Regex messageParser)
{
NormalizedCompilerStatus ret;
ret.code = NormalizedCompilerStatusCode.UnknownTypeOrNamespace;
var dm = messageParser.Match(outputMatch.Groups["message"].Value);
ret.details = "EntityName=" + dm.Groups["type_name"].Value + "\n"
+ "Script=" + outputMatch.Groups["filename"].Value + "\n"
+ "Line=" + outputMatch.Groups["line"].Value + "\n"
+ "Column=" + outputMatch.Groups["column"].Value;
return ret;
}
protected static NormalizedCompilerStatus NormalizeUnknownTypeMemberOfNamespaceError(Match outputMatch, Regex messageParser)
{
NormalizedCompilerStatus ret;
ret.code = NormalizedCompilerStatusCode.UnknownTypeOrNamespace;
var dm = messageParser.Match(outputMatch.Groups["message"].Value);
ret.details = "EntityName=" + dm.Groups["namespace"].Value + "." + dm.Groups["type_name"].Value + "\n"
+ "Script=" + outputMatch.Groups["filename"].Value + "\n"
+ "Line=" + outputMatch.Groups["line"].Value + "\n"
+ "Column=" + outputMatch.Groups["column"].Value;
return ret;
}
}
}