docs: 优化 LexicalError 类的文档注释

- 为 LexicalError 类添加详细的类文档注释,说明其用途
- 为所有字段和构造方法添加规范的参数注释
- 优化 toString 方法的注释,明确其返回值内容
This commit is contained in:
Luke 2025-07-16 10:57:13 +08:00
parent 85d3b129ae
commit eae66eac8c

View File

@ -1,11 +1,41 @@
package org.jcnc.snow.compiler.lexer.core; package org.jcnc.snow.compiler.lexer.core;
/**
* 表示词法分析过程中发生的错误信息
* <p>
* 该类用于封装词法分析lexical analysis阶段发现的错误包括错误位置文件名行号列号
* 以及错误描述信息便于定位和调试
* </p>
*/
public class LexicalError { public class LexicalError {
/**
* 出错所在的源文件名
*/
private final String file; private final String file;
/**
* 出错所在的行号从1开始
*/
private final int line; private final int line;
/**
* 出错所在的列号从1开始
*/
private final int column; private final int column;
/**
* 错误的详细描述信息
*/
private final String message; 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) { public LexicalError(String file, int line, int column, String message) {
this.file = file; this.file = file;
this.line = line; this.line = line;
@ -13,6 +43,11 @@ public class LexicalError {
this.message = message; this.message = message;
} }
/**
* 以易于阅读的字符串形式返回错误信息
*
* @return 格式化的错误信息字符串包含文件名行号列号和错误描述
*/
@Override @Override
public String toString() { public String toString() {
return file + ": 行 " + line + ", 列 " + column + ": " + message; return file + ": 行 " + line + ", 列 " + column + ": " + message;