Show file name in error messages, to handle errors from modules easier

This commit is contained in:
2018-12-07 14:51:02 +01:00
parent edd352e62a
commit b0450d3bf5
7 changed files with 31 additions and 23 deletions

View File

@@ -8,15 +8,17 @@ namespace Upsilon
{
public class Diagnostics
{
public string FileName { get; }
public SourceText ScriptString { get; }
public readonly List<DiagnosticsMessage> Errors = new List<DiagnosticsMessage>();
public readonly List<DiagnosticsMessage> Warnings = new List<DiagnosticsMessage>();
public bool ThrowsOnError { get; }
public Diagnostics(SourceText scriptString, bool throwsOnError)
public Diagnostics(SourceText scriptString, bool throwsOnError, string fileName)
{
ScriptString = scriptString;
ThrowsOnError = throwsOnError;
FileName = fileName;
}
public void Log(DiagnosticLevel level, string message, TextSpan location)
@@ -33,7 +35,7 @@ namespace Upsilon
{
var linePos = ScriptString.GetLinePosition(location.Start);
var line = ScriptString.GetLine(linePos.Line);
throw new ParseException(message, linePos.Line, linePos.Pos, line);
throw new ParseException(FileName, message, linePos.Line, linePos.Pos, line);
}
Log(DiagnosticLevel.Error, message, location);
}