Make log_css_error in parser.rs take a &ParserContext argument and call this method

This commit is contained in:
GauriGNaik 2015-11-07 20:14:57 -05:00 committed by Josh Matthews
parent a8cbc28643
commit afdc60fa57
5 changed files with 9 additions and 12 deletions

View file

@ -40,7 +40,7 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
let pos = range.start;
let message = format!("Unsupported @font-face descriptor declaration: '{}'",
iter.input.slice(range));
log_css_error(iter.input, pos, &*message);
log_css_error(iter.input, pos, &*message, context);
}
Ok(FontFaceDescriptorDeclaration::Family(value)) => {
family = Some(value);

View file

@ -43,10 +43,6 @@ impl<'a> ParserContext<'a> {
/// Defaults to a no-op.
/// Set a `RUST_LOG=style::errors` environment variable
/// to log CSS parse errors to stderr.
pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str) {
if log_enabled!(log::LogLevel::Info) {
let location = input.source_location(position);
// TODO eventually this will got into a "web console" or something.
info!("{}:{} {}", location.line, location.column, message)
}
pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str, parsercontext: &ParserContext) {
parsercontext.error_reporter.report_error(input, position, message);
}

View file

@ -5739,7 +5739,7 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
let pos = range.start;
let message = format!("Unsupported property declaration: '{}'",
iter.input.slice(range));
log_css_error(iter.input, pos, &*message);
log_css_error(iter.input, pos, &*message, &context);
}
}
}

View file

@ -108,7 +108,7 @@ impl Stylesheet {
pub fn from_str(css: &str, base_url: Url, origin: Origin,
error_reporter: Box<ParseErrorReporter + Send>) -> Stylesheet {
let rule_parser = TopLevelRuleParser {
context: ParserContext::new(origin, &base_url, error_reporter),
context: ParserContext::new(origin, &base_url, error_reporter.clone()),
state: Cell::new(State::Start),
};
let mut input = Parser::new(css);
@ -131,7 +131,8 @@ impl Stylesheet {
Err(range) => {
let pos = range.start;
let message = format!("Invalid rule: '{}'", iter.input.slice(range));
log_css_error(iter.input, pos, &*message);
let context = ParserContext::new(origin, &base_url, error_reporter.clone());
log_css_error(iter.input, pos, &*message, &context);
}
}
}
@ -329,7 +330,7 @@ fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> Vec<CSSRul
Err(range) => {
let pos = range.start;
let message = format!("Unsupported rule: '{}'", iter.input.slice(range));
log_css_error(iter.input, pos, &*message);
log_css_error(iter.input, pos, &*message, &context);
}
}
}

View file

@ -271,7 +271,7 @@ impl ViewportRule {
let pos = range.start;
let message = format!("Unsupported @viewport descriptor declaration: '{}'",
input.slice(range));
log_css_error(input, pos, &*message);
log_css_error(input, pos, &*message, &context);
}
Ok(ViewportRule { declarations: valid_declarations.iter().cascade() })