mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
style: Avoid cloning all over the error reporter.
This commit is contained in:
parent
eaf27ccfa0
commit
b4de69e3eb
36 changed files with 186 additions and 154 deletions
|
@ -11,16 +11,16 @@ use log;
|
|||
use servo_url::ServoUrl;
|
||||
|
||||
/// A generic trait for an error reporter.
|
||||
pub trait ParseErrorReporter {
|
||||
pub trait ParseErrorReporter : Sync + Send {
|
||||
/// Called the style engine detects an error.
|
||||
///
|
||||
/// Returns the current input being parsed, the source position it was
|
||||
/// reported from, and a message.
|
||||
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str, url: &ServoUrl);
|
||||
/// Clone this error reporter.
|
||||
///
|
||||
/// TODO(emilio): I'm pretty sure all the box shenanigans can go away.
|
||||
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync>;
|
||||
fn report_error(&self,
|
||||
input: &mut Parser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl);
|
||||
}
|
||||
|
||||
/// An error reporter that reports the errors to the `info` log channel.
|
||||
|
@ -28,15 +28,14 @@ pub trait ParseErrorReporter {
|
|||
/// TODO(emilio): The name of this reporter is a lie, and should be renamed!
|
||||
pub struct StdoutErrorReporter;
|
||||
impl ParseErrorReporter for StdoutErrorReporter {
|
||||
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str,
|
||||
url: &ServoUrl) {
|
||||
fn report_error(&self,
|
||||
input: &mut Parser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl) {
|
||||
if log_enabled!(log::LogLevel::Info) {
|
||||
let location = input.source_location(position);
|
||||
info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message)
|
||||
}
|
||||
}
|
||||
|
||||
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
|
||||
Box::new(StdoutErrorReporter)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue