pub struct ErrorReporter { /* private fields */ }Expand description
Holds metadata about the input, allows to report errors to the user.
This structure should be created before the parsing process and will provide
metadata required for the AnnotatedError.
If the reporter contains a file path, then this path must be valid UTF-8. This is needed because the file path is printed on the console when an error is reported.
Implementations§
Source§impl ErrorReporter
impl ErrorReporter
Sourcepub fn input_file(path: String, content: String) -> ErrorReporter
pub fn input_file(path: String, content: String) -> ErrorReporter
Given a file path and its content, creates a new ErrorReporter.
path is not checked to be a valid path.
Sourcepub fn non_file_input(content: String) -> ErrorReporter
pub fn non_file_input(content: String) -> ErrorReporter
Creates an ErrorReporter with no file path, just its content.
This can be usefull in situations in which non-file inputs such as STDIN are processed.
Sourcepub fn from_path(path: String) -> Result<ErrorReporter, IOError>
pub fn from_path(path: String) -> Result<ErrorReporter, IOError>
Reads the content of path, and creates an ErrorReporter with it.
Sourcepub fn spanned_str(&self) -> SpannedStr<'_>
pub fn spanned_str(&self) -> SpannedStr<'_>
Returns the SpannedStr associated to the whole input.
§Example
use lisbeth_error::reporter::ErrorReporter;
let file = ErrorReporter::non_file_input("Hello, world".to_string());
assert_eq!(file.spanned_str().content(), "Hello, world");Sourcepub fn format_error<'a>(&'a self, err: &'a AnnotatedError) -> FormattedError<'a>
pub fn format_error<'a>(&'a self, err: &'a AnnotatedError) -> FormattedError<'a>
Constructs a FormattedError from an AnnotatedError.
The returned value can finally be printed to the user.