2024-03-13 16:39:00 +08:00
|
|
|
|
namespace Canon.Core.Exceptions;
|
2024-04-04 21:25:11 +08:00
|
|
|
|
using Enums;
|
2024-03-13 16:39:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 词法分析中引发的异常
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LexemeException : Exception
|
|
|
|
|
{
|
2024-04-04 21:25:11 +08:00
|
|
|
|
public LexemeErrorType ErrorType { get; }
|
|
|
|
|
public uint Line { get; }
|
|
|
|
|
public uint CharPosition { get; }
|
2024-03-13 16:39:00 +08:00
|
|
|
|
public LexemeException() { }
|
|
|
|
|
|
|
|
|
|
public LexemeException(string message) : base(message) { }
|
|
|
|
|
|
|
|
|
|
public LexemeException(string message, Exception innerException) :
|
|
|
|
|
base(message, innerException) { }
|
|
|
|
|
|
2024-04-04 21:25:11 +08:00
|
|
|
|
/// <param name="errorType">错误类型</param>
|
2024-03-13 16:39:00 +08:00
|
|
|
|
/// <param name="line">单词的行号</param>
|
|
|
|
|
/// <param name="charPosition">单词的列号</param>
|
|
|
|
|
/// <param name="message">错误信息</param>
|
2024-04-04 21:25:11 +08:00
|
|
|
|
public LexemeException(LexemeErrorType errorType, uint line, uint charPosition, string message) :
|
|
|
|
|
base("line:" + line + ", charPosition:" + charPosition + " :" + message)
|
|
|
|
|
{
|
|
|
|
|
ErrorType = errorType;
|
|
|
|
|
Line = line;
|
|
|
|
|
CharPosition = charPosition;
|
|
|
|
|
}
|
2024-03-13 16:39:00 +08:00
|
|
|
|
|
2024-04-04 21:25:11 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"LexemeException: ErrorType={ErrorType}, Line={Line}, CharPosition={CharPosition}, Message={Message}\n";
|
|
|
|
|
}
|
2024-03-13 16:39:00 +08:00
|
|
|
|
}
|