From eae66eac8cf2f93c8c3d5ad1fa070ca5010c7d91 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 16 Jul 2025 10:57:13 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=BC=98=E5=8C=96=20LexicalError=20?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E6=96=87=E6=A1=A3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 LexicalError 类添加详细的类文档注释,说明其用途 - 为所有字段和构造方法添加规范的参数注释 - 优化 toString 方法的注释,明确其返回值内容 --- .../compiler/lexer/core/LexicalError.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/jcnc/snow/compiler/lexer/core/LexicalError.java b/src/main/java/org/jcnc/snow/compiler/lexer/core/LexicalError.java index 81ac9ee..b036fa0 100644 --- a/src/main/java/org/jcnc/snow/compiler/lexer/core/LexicalError.java +++ b/src/main/java/org/jcnc/snow/compiler/lexer/core/LexicalError.java @@ -1,11 +1,41 @@ package org.jcnc.snow.compiler.lexer.core; +/** + * 表示词法分析过程中发生的错误信息。 + *

+ * 该类用于封装词法分析(lexical analysis)阶段发现的错误,包括错误位置(文件名、行号、列号) + * 以及错误描述信息,便于定位和调试。 + *

+ */ public class LexicalError { + /** + * 出错所在的源文件名。 + */ private final String file; + + /** + * 出错所在的行号(从1开始)。 + */ private final int line; + + /** + * 出错所在的列号(从1开始)。 + */ private final int column; + + /** + * 错误的详细描述信息。 + */ private final String message; + /** + * 构造一个新的 {@code LexicalError} 实例。 + * + * @param file 出错的源文件名 + * @param line 出错所在的行号(从1开始) + * @param column 出错所在的列号(从1开始) + * @param message 错误的详细描述信息 + */ public LexicalError(String file, int line, int column, String message) { this.file = file; this.line = line; @@ -13,6 +43,11 @@ public class LexicalError { this.message = message; } + /** + * 以易于阅读的字符串形式返回错误信息。 + * + * @return 格式化的错误信息字符串,包含文件名、行号、列号和错误描述 + */ @Override public String toString() { return file + ": 行 " + line + ", 列 " + column + ": " + message;