Exception throwing when required, and fixes for unit tests

This commit is contained in:
2018-11-26 17:23:56 +01:00
parent 74da87d936
commit b7d01b02f1
14 changed files with 73 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Upsilon.BaseTypes;
using Upsilon.Exceptions;
using Upsilon.Parser;
using Upsilon.Text;
@@ -9,10 +10,12 @@ namespace Upsilon
{
public SourceText ScriptString { get; }
public readonly List<DiagnosticsMessage> Messages = new List<DiagnosticsMessage>();
public bool ThrowsOnError { get; }
public Diagnostics(SourceText scriptString)
public Diagnostics(SourceText scriptString, bool throwsOnError)
{
ScriptString = scriptString;
ThrowsOnError = throwsOnError;
}
public void Log(DiagnosticLevel level, string message, TextSpan location)
@@ -22,6 +25,12 @@ namespace Upsilon
public void LogError(string message, TextSpan location)
{
if (ThrowsOnError)
{
var linePos = ScriptString.GetLinePosition(location.Start);
var line = ScriptString.GetLine(linePos.Line);
throw new ParseException(message, linePos.Line, linePos.Pos, line);
}
Log(DiagnosticLevel.Error, message, location);
}