This is a visualizing tool that locates the source of errors within sequences and outputs formatted results, designed to assist users and developers in quickly identifying input that triggers errors.
/// Creates an ErrorData instance
/// 创建一个 ErrorData 实例
fn ErrorData::make(
err_type~ : String? = None,
err_msg : String,
err_pos~ : Int = -1,
err_offset~ : Int = 0
) -> ErrorData/// Construct a Sequence instance from array
/// 从数组构造一个 Sequence
pub fn[T : Show] Sequence::from_array(arr: Array[T], join~: String = " ") -> Sequence[T]
/// Construct a Sequence instance from string
/// 从字符串构造一个 Sequence
pub fn Sequence::from_string(str: String) -> Sequence[Char]/// Generate visual error markers to show error position, markers, and error messages
/// 生成可视化错误标记,展示错误位置、标记和错误信息
pub fn[T : Show] ErrorData::mark(
self : ErrorData,
seq : Sequence[T],
marker~ : Char = '^',
gen_msg~ : (String?, String) -> String = gen_err_msg
) -> String
/// format error message into standard format: "Error(type): message"
/// 格式化错误信息为标准格式:"Error(type): message"
fn gen_err_msg(err_type: String?, err_msg: String) -> StringUsers can format error messages into custom format by providing a custom function with same signature as gen_err_msg.用户可以通过提供与 gen_err_msg 具有相同函数签名的自定义函数,将错误信息格式化为自定义格式。let data = ErrorData::make(
err_type=Some("TypeError"),
err_msg="Invalid token",
err_pos=1,
err_offset=0
)
let arr_seq = Sequence::from_array(["hello", "world"], " ")
println(data.mark(arr_seq))hello world
^^^^^
Error(TypeError): Invalid tokenpub struct ErrorData {
err_type : String?
err_msg : String
err_pos : Int
err_offset : Int
}type Sequence[T]Install
Download zipThis is a visualizing tool that locates the source of errors within sequences and outputs formatted results, designed to assist users and developers in quickly identifying input that triggers errors.