Log CSS errors on stderr, with serialized bits of CSS.

This commit is contained in:
Simon Sapin 2013-10-24 17:43:48 +02:00
parent 352acbb833
commit abb1bdefee
3 changed files with 23 additions and 9 deletions

View file

@ -22,5 +22,5 @@ impl<T, I: Iterator<Result<T, SyntaxError>>> Iterator<T> for ErrorLoggerIterator
pub fn log_css_error(location: SourceLocation, message: &str) { pub fn log_css_error(location: SourceLocation, message: &str) {
// TODO eventually this will got into a "web console" or something. // TODO eventually this will got into a "web console" or something.
info!("{:u}:{:u} {:s}", location.line, location.column, message) error!("{:u}:{:u} {:s}", location.line, location.column, message)
} }

View file

@ -861,8 +861,12 @@ pub fn parse_property_declaration_list<I: Iterator<Node>>(input: I) -> PropertyD
Declaration(Declaration{ location: l, name: n, value: v, important: i}) => { Declaration(Declaration{ location: l, name: n, value: v, important: i}) => {
// TODO: only keep the last valid declaration for a given name. // TODO: only keep the last valid declaration for a given name.
let list = if i { &mut important } else { &mut normal }; let list = if i { &mut important } else { &mut normal };
if !PropertyDeclaration::parse(n, v, list) { match PropertyDeclaration::parse(n, v, list) {
log_css_error(l, "Invalid property declaration") UnknownProperty => log_css_error(l, format!(
"Unsupported property: {}:{}", n, v.iter().to_css())),
InvalidValue => log_css_error(l, format!(
"Invalid value: {}:{}", n, v.iter().to_css())),
ValidDeclaration => (),
} }
} }
} }
@ -909,15 +913,22 @@ pub enum PropertyDeclaration {
% endfor % endfor
} }
enum PropertyDeclarationParseResult {
UnknownProperty,
InvalidValue,
ValidDeclaration,
}
impl PropertyDeclaration { impl PropertyDeclaration {
pub fn parse(name: &str, value: &[ComponentValue], pub fn parse(name: &str, value: &[ComponentValue],
result_list: &mut ~[PropertyDeclaration]) -> bool { result_list: &mut ~[PropertyDeclaration]) -> PropertyDeclarationParseResult {
match name.to_ascii_lower().as_slice() { match name.to_ascii_lower().as_slice() {
% for property in LONGHANDS: % for property in LONGHANDS:
"${property.name}" => result_list.push(${property.ident}_declaration( "${property.name}" => result_list.push(${property.ident}_declaration(
match longhands::${property.ident}::parse_declared(value) { match longhands::${property.ident}::parse_declared(value) {
Some(value) => value, Some(value) => value,
None => return false, None => return InvalidValue,
} }
)), )),
% endfor % endfor
@ -949,13 +960,13 @@ impl PropertyDeclaration {
)); ));
% endfor % endfor
}, },
None => return false, None => return InvalidValue,
} }
}, },
% endfor % endfor
_ => return false, // Unknown property _ => return UnknownProperty,
} }
true ValidDeclaration
} }
} }

View file

@ -112,12 +112,15 @@ impl Stylesheet {
pub fn parse_style_rule(rule: QualifiedRule, parent_rules: &mut ~[CSSRule], pub fn parse_style_rule(rule: QualifiedRule, parent_rules: &mut ~[CSSRule],
namespaces: &NamespaceMap) { namespaces: &NamespaceMap) {
let QualifiedRule{location: location, prelude: prelude, block: block} = rule; let QualifiedRule{location: location, prelude: prelude, block: block} = rule;
// FIXME: avoid doing this for valid selectors
let serialized = prelude.iter().to_css();
match selectors::parse_selector_list(prelude, namespaces) { match selectors::parse_selector_list(prelude, namespaces) {
Some(selectors) => parent_rules.push(CSSStyleRule(StyleRule{ Some(selectors) => parent_rules.push(CSSStyleRule(StyleRule{
selectors: selectors, selectors: selectors,
declarations: properties::parse_property_declaration_list(block.move_iter()) declarations: properties::parse_property_declaration_list(block.move_iter())
})), })),
None => log_css_error(location, "Unsupported CSS selector."), None => log_css_error(location, format!(
"Invalid/unsupported selector: {}", serialized)),
} }
} }