This commit is contained in:
Jelle Luteijn 2022-05-15 11:19:49 +02:00
parent 16e76d6b31
commit 484dbfc9d9
529 changed files with 113694 additions and 0 deletions

View file

@ -0,0 +1,116 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Security.Permissions;
using AspClassic.Scripting.Utils;
namespace AspClassic.Scripting;
[Serializable]
public class SyntaxErrorException : Exception
{
private SourceSpan _span;
private string _sourceCode;
private string _sourceLine;
private string _sourcePath;
private Severity _severity;
private int _errorCode;
public SourceSpan RawSpan => _span;
public string SourceCode => _sourceCode;
public string SourcePath => _sourcePath;
public Severity Severity => _severity;
public int Line => _span.Start.Line;
public int Column => _span.Start.Column;
public int ErrorCode => _errorCode;
public SyntaxErrorException()
{
}
public SyntaxErrorException(string message)
: base(message)
{
}
public SyntaxErrorException(string message, Exception innerException)
: base(message, innerException)
{
}
public SyntaxErrorException(string message, SourceUnit sourceUnit, SourceSpan span, int errorCode, Severity severity)
: base(message)
{
ContractUtils.RequiresNotNull(message, "message");
_span = span;
_severity = severity;
_errorCode = errorCode;
if (sourceUnit != null)
{
_sourcePath = sourceUnit.Path;
try
{
_sourceCode = sourceUnit.GetCode();
_sourceLine = sourceUnit.GetCodeLine(Line);
}
catch (IOException)
{
}
}
}
public SyntaxErrorException(string message, string path, string code, string line, SourceSpan span, int errorCode, Severity severity)
: base(message)
{
ContractUtils.RequiresNotNull(message, "message");
_span = span;
_severity = severity;
_errorCode = errorCode;
_sourcePath = path;
_sourceCode = code;
_sourceLine = line;
}
protected SyntaxErrorException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
_span = (SourceSpan)info.GetValue("Span", typeof(SourceSpan));
_sourceCode = info.GetString("SourceCode");
_sourcePath = info.GetString("SourcePath");
_severity = (Severity)info.GetValue("Severity", typeof(Severity));
_errorCode = info.GetInt32("ErrorCode");
}
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
ContractUtils.RequiresNotNull(info, "info");
base.GetObjectData(info, context);
info.AddValue("Span", _span);
info.AddValue("SourceCode", _sourceCode);
info.AddValue("SourcePath", _sourcePath);
info.AddValue("Severity", _severity);
info.AddValue("ErrorCode", _errorCode);
}
public string GetSymbolDocumentName()
{
return _sourcePath;
}
public string GetCodeLine()
{
return _sourceLine;
}
}