Struct CompilerError
pub struct CompilerError {
pub error_code: ErrorCode,
pub message: String,
pub line: usize,
pub column: usize,
pub position: usize,
pub token_length: Option<usize>,
}
Expand description
Represents a compiler error with a message, line number, column number, position, and token length
Fields§
§error_code: ErrorCode
The structured error code for this error
message: String
The error message
line: usize
The line number where the error occurred
column: usize
The column number where the error occurred
position: usize
The byte offset position of the error in the source code
token_length: Option<usize>
The length of the token causing the error, if applicable
Implementations§
§impl CompilerError
impl CompilerError
pub fn new(
error_code: ErrorCode,
message: String,
line: usize,
column: usize,
position: usize,
token_length: Option<usize>,
) -> CompilerError
pub fn new( error_code: ErrorCode, message: String, line: usize, column: usize, position: usize, token_length: Option<usize>, ) -> CompilerError
Creates a new CompilerError with the given error code, message, line number, column number, position, and token length
§Arguments
error_code
- The structured error code for this errormessage
- The error messageline
- The line number where the error occurredcolumn
- The column number where the error occurredposition
- The byte offset position of the errortoken_length
- The length of the token, if applicable
§Returns
A new CompilerError object
§Example
use slang_error::{CompilerError, ErrorCode};
let error = CompilerError::new(ErrorCode::ExpectedSemicolon, "Syntax error".to_string(), 10, 5, 0, Some(1));
pub fn format_for_display(&self, line_info: &LineInfo<'_>) -> String
pub fn format_for_display(&self, line_info: &LineInfo<'_>) -> String
Format an error message with line information and source code snippet
This creates a nicely formatted error message similar to Rust’s compiler errors, with line numbers, source code context, and arrows pointing to the error location.
§Arguments
line_info
- LineInfo object for the source code context
§Returns
A formatted error message string