auto merge of #1156 : SimonSapin/servo/logging, r=kmcallister

(Ab)using `error!()` because it’s enabled by default.
This commit is contained in:
bors-servo 2013-10-31 17:55:14 -07:00
commit a72d055800
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) {
// 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}) => {
// TODO: only keep the last valid declaration for a given name.
let list = if i { &mut important } else { &mut normal };
if !PropertyDeclaration::parse(n, v, list) {
log_css_error(l, "Invalid property declaration")
match PropertyDeclaration::parse(n, v, list) {
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
}
enum PropertyDeclarationParseResult {
UnknownProperty,
InvalidValue,
ValidDeclaration,
}
impl PropertyDeclaration {
pub fn parse(name: &str, value: &[ComponentValue],
result_list: &mut ~[PropertyDeclaration]) -> bool {
result_list: &mut ~[PropertyDeclaration]) -> PropertyDeclarationParseResult {
match name.to_ascii_lower().as_slice() {
% for property in LONGHANDS:
"${property.name}" => result_list.push(${property.ident}_declaration(
match longhands::${property.ident}::parse_declared(value) {
Some(value) => value,
None => return false,
None => return InvalidValue,
}
)),
% endfor
@ -949,13 +960,13 @@ impl PropertyDeclaration {
));
% endfor
},
None => return false,
None => return InvalidValue,
}
},
% 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],
namespaces: &NamespaceMap) {
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) {
Some(selectors) => parent_rules.push(CSSStyleRule(StyleRule{
selectors: selectors,
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)),
}
}