From e191c1e077d880eaa67660433b1a2ecdf3eff722 Mon Sep 17 00:00:00 2001 From: Lan_G <2911328695@qq.com> Date: Wed, 13 Mar 2024 16:39:00 +0800 Subject: [PATCH] add: exceptions(#7) Reviewed-on: https://git.rrricardo.top/PostGuard/Canon/pulls/7 Co-authored-by: Lan_G <2911328695@qq.com> Co-committed-by: Lan_G <2911328695@qq.com> --- Canon.Core/Exceptions/GrammarException.cs | 12 +++++++++++ Canon.Core/Exceptions/LexemeException.cs | 25 ++++++++++++++++++++++ Canon.Core/Exceptions/SemanticException.cs | 12 +++++++++++ 3 files changed, 49 insertions(+) create mode 100644 Canon.Core/Exceptions/GrammarException.cs create mode 100644 Canon.Core/Exceptions/LexemeException.cs create mode 100644 Canon.Core/Exceptions/SemanticException.cs diff --git a/Canon.Core/Exceptions/GrammarException.cs b/Canon.Core/Exceptions/GrammarException.cs new file mode 100644 index 0000000..59fa1de --- /dev/null +++ b/Canon.Core/Exceptions/GrammarException.cs @@ -0,0 +1,12 @@ +namespace Canon.Core.Exceptions; +/// +/// 语法分析中引发的异常 +/// +public class GrammarException : Exception +{ + public GrammarException() { } + + public GrammarException(string message) : base(message) { } + + public GrammarException(string message, Exception innerException) : base(message, innerException) { } +} diff --git a/Canon.Core/Exceptions/LexemeException.cs b/Canon.Core/Exceptions/LexemeException.cs new file mode 100644 index 0000000..b20c4ed --- /dev/null +++ b/Canon.Core/Exceptions/LexemeException.cs @@ -0,0 +1,25 @@ +namespace Canon.Core.Exceptions; +/// +/// 词法分析中引发的异常 +/// +public class LexemeException : Exception +{ + public LexemeException() { } + + public LexemeException(string message) : base(message) { } + + public LexemeException(string message, Exception innerException) : + base(message, innerException) { } + + /// 单词的行号 + /// 单词的列号 + /// 错误信息 + public LexemeException(uint line, uint charPosition, string message) : + base("line:" + line + ", charPosition:" + charPosition + " :" + message) { } + + 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) { } +} diff --git a/Canon.Core/Exceptions/SemanticException.cs b/Canon.Core/Exceptions/SemanticException.cs new file mode 100644 index 0000000..ddb9201 --- /dev/null +++ b/Canon.Core/Exceptions/SemanticException.cs @@ -0,0 +1,12 @@ +namespace Canon.Core.Exceptions; +/// +/// 语义分析中引发的异常 +/// +public class SemanticException : Exception +{ + public SemanticException() : base() { } + + public SemanticException(string message) : base(message) { } + + public SemanticException(string message, Exception innerException) : base(message, innerException) { } +}