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:
Huaps
2024-04-04 21:25:11 +08:00
committed by jackfiled
parent ccd1899739
commit c4189fd1b2
13 changed files with 955 additions and 426 deletions

View File

@@ -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";
}
}