forked from jasder/antlr
Update build message processing for the ANTLR 4 message formatting
This commit is contained in:
parent
4a3b2cdffc
commit
b36728df10
|
@ -304,7 +304,7 @@ namespace Antlr4.Build.Tasks
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsFatalException(Exception exception)
|
internal static bool IsFatalException(Exception exception)
|
||||||
{
|
{
|
||||||
while (exception != null)
|
while (exception != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,17 +35,19 @@ namespace Antlr4.Build.Tasks
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal struct BuildMessage
|
internal struct BuildMessage
|
||||||
{
|
{
|
||||||
private static readonly Regex BuildMessageFormat = new Regex(@"^\s*(?<FILE>.*)\((?<LINE>[0-9]+),(?<COLUMN>[0-9]+)\) : (?<SEVERITY>[a-z]+)\s*(?<CODE>[0-9]+) : (?<MESSAGE>.*)$", RegexOptions.Compiled);
|
private static readonly Regex BuildMessageFormat = new Regex(@"^\s*(?<SEVERITY>[a-z]+)\((?<CODE>[0-9]+)\):\s*((?<FILE>.*):(?<LINE>[0-9]+):(?<COLUMN>[0-9]+):)?\s*(?:syntax error:\s*)?(?<MESSAGE>.*)$", RegexOptions.Compiled);
|
||||||
|
|
||||||
public BuildMessage(string message)
|
public BuildMessage(string message)
|
||||||
: this(TraceLevel.Error, message, null, 0, 0)
|
: this(TraceLevel.Error, message, null, 0, 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Match match = BuildMessageFormat.Match(message);
|
Match match = BuildMessageFormat.Match(message);
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
FileName = match.Groups["FILE"].Value;
|
FileName = match.Groups["FILE"].Length > 0 ? match.Groups["FILE"].Value : "";
|
||||||
LineNumber = int.Parse(match.Groups["LINE"].Value);
|
LineNumber = match.Groups["LINE"].Length > 0 ? int.Parse(match.Groups["LINE"].Value) : 0;
|
||||||
ColumnNumber = int.Parse(match.Groups["COLUMN"].Value);
|
ColumnNumber = match.Groups["COLUMN"].Length > 0 ? int.Parse(match.Groups["COLUMN"].Value) + 1 : 0;
|
||||||
|
|
||||||
switch (match.Groups["SEVERITY"].Value)
|
switch (match.Groups["SEVERITY"].Value)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +65,16 @@ namespace Antlr4.Build.Tasks
|
||||||
int code = int.Parse(match.Groups["CODE"].Value);
|
int code = int.Parse(match.Groups["CODE"].Value);
|
||||||
Message = string.Format("AC{0:0000}: {1}", code, match.Groups["MESSAGE"].Value);
|
Message = string.Format("AC{0:0000}: {1}", code, match.Groups["MESSAGE"].Value);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (Antlr4ClassGenerationTask.IsFatalException(ex))
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuildMessage(TraceLevel severity, string message, string fileName, int lineNumber, int columnNumber)
|
public BuildMessage(TraceLevel severity, string message, string fileName, int lineNumber, int columnNumber)
|
||||||
|
|
Loading…
Reference in New Issue