lexical-parser (#15)
add: 词法分析器剩下数字、标识符的细节处理以及错误处理 Co-authored-by: duqoo <92306417+duqoo@users.noreply.github.com> Reviewed-on: PostGuard/Canon#15 Co-authored-by: Huaps <1183155719@qq.com> Co-committed-by: Huaps <1183155719@qq.com>
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
namespace Canon.Core.Exceptions;
|
||||
using Enums;
|
||||
/// <summary>
|
||||
/// 词法分析中引发的异常
|
||||
/// </summary>
|
||||
public class LexemeException : Exception
|
||||
{
|
||||
public LexemeErrorType ErrorType { get; }
|
||||
public uint Line { get; }
|
||||
public uint CharPosition { get; }
|
||||
public LexemeException() { }
|
||||
|
||||
public LexemeException(string message) : base(message) { }
|
||||
@@ -11,15 +15,20 @@ public class LexemeException : Exception
|
||||
public LexemeException(string message, Exception innerException) :
|
||||
base(message, innerException) { }
|
||||
|
||||
/// <param name="errorType">错误类型</param>
|
||||
/// <param name="line">单词的行号</param>
|
||||
/// <param name="charPosition">单词的列号</param>
|
||||
/// <param name="message">错误信息</param>
|
||||
public LexemeException(uint line, uint charPosition, string message) :
|
||||
base("line:" + line + ", charPosition:" + charPosition + " :" + message) { }
|
||||
public LexemeException(LexemeErrorType errorType, uint line, uint charPosition, string message) :
|
||||
base("line:" + line + ", charPosition:" + charPosition + " :" + message)
|
||||
{
|
||||
ErrorType = errorType;
|
||||
Line = line;
|
||||
CharPosition = charPosition;
|
||||
}
|
||||
|
||||
public LexemeException(uint line, uint charPosition, Exception innerException) :
|
||||
base("line:" + line + ", charPosition:" + charPosition + " : ", innerException) { }
|
||||
|
||||
public LexemeException(uint line, uint charPosition, string message, Exception innerException) :
|
||||
base("line:" + line + ", charPosition:" + charPosition + " :" + message, innerException) { }
|
||||
public override string ToString()
|
||||
{
|
||||
return $"LexemeException: ErrorType={ErrorType}, Line={Line}, CharPosition={CharPosition}, Message={Message}\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user