Exception throwing when required, and fixes for unit tests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user