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>
|
2024-05-13 22:29:32 +08:00
|
|
|
|
public class LexemeException : CanonException
|
2024-03-13 16:39:00 +08:00
|
|
|
|
{
|
2024-04-04 21:25:11 +08:00
|
|
|
|
public LexemeErrorType ErrorType { get; }
|
2024-05-13 22:29:32 +08:00
|
|
|
|
|
2024-04-04 21:25:11 +08:00
|
|
|
|
public uint Line { get; }
|
2024-03-13 16:39:00 +08:00
|
|
|
|
|
2024-05-13 22:29:32 +08:00
|
|
|
|
public uint CharPosition { get; }
|
2024-03-13 16:39:00 +08:00
|
|
|
|
|
2024-05-13 22:29:32 +08:00
|
|
|
|
private readonly string _message;
|
2024-03-13 16:39:00 +08:00
|
|
|
|
|
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-05-13 22:29:32 +08:00
|
|
|
|
public LexemeException(LexemeErrorType errorType, uint line, uint charPosition, string message)
|
2024-04-04 21:25:11 +08:00
|
|
|
|
{
|
|
|
|
|
ErrorType = errorType;
|
|
|
|
|
Line = line;
|
|
|
|
|
CharPosition = charPosition;
|
2024-05-13 22:29:32 +08:00
|
|
|
|
_message = message;
|
2024-04-04 21:25:11 +08:00
|
|
|
|
}
|
2024-03-13 16:39:00 +08:00
|
|
|
|
|
2024-05-13 22:29:32 +08:00
|
|
|
|
public override string Message => ToString();
|
|
|
|
|
|
2024-04-04 21:25:11 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2024-05-13 22:29:32 +08:00
|
|
|
|
return $"LexemeException: ErrorType={ErrorType}, Line={Line}, CharPosition={CharPosition}, Message={_message}\n";
|
2024-04-04 21:25:11 +08:00
|
|
|
|
}
|
2024-03-13 16:39:00 +08:00
|
|
|
|
}
|