reindent html_builder loops

This commit is contained in:
Margaret Meyerhofer 2012-06-22 15:00:03 -07:00
parent 105cd0ac9a
commit 7508d6d2a1

View file

@ -18,36 +18,36 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: str, -value: str) {
scope.read(node) { scope.read(node) {
|node_contents| |node_contents|
alt *node_contents.kind { alt *node_contents.kind {
Element(element) { Element(element) {
element.attrs.push(~Attr(copy key, copy value)); element.attrs.push(~Attr(copy key, copy value));
alt *element.kind { alt *element.kind {
HTMLImageElement(img) if key == "width" { HTMLImageElement(img) if key == "width" {
alt int::from_str(value) { alt int::from_str(value) {
none { none {
// Drop on the floor. // Drop on the floor.
} }
some(s) { img.size.width = geometry::px_to_au(s); } some(s) { img.size.width = geometry::px_to_au(s); }
}
}
HTMLImageElement(img) if key == "height" {
alt int::from_str(value) {
none {
// Drop on the floor.
}
some(s) {
img.size.height = geometry::px_to_au(s);
}
}
}
HTMLDivElement | HTMLImageElement(*) | HTMLHeadElement | UnknownElement {
// Drop on the floor.
}
} }
}
HTMLImageElement(img) if key == "height" {
alt int::from_str(value) {
none {
// Drop on the floor.
}
some(s) {
img.size.height = geometry::px_to_au(s);
}
}
}
HTMLDivElement | HTMLImageElement(*) | HTMLHeadElement | UnknownElement {
// Drop on the floor.
}
} }
}
Text(*) { Text(*) {
fail "attempt to link up an attribute to a text node" fail "attempt to link up an attribute to a text node"
} }
} }
} }
} }
@ -72,37 +72,38 @@ fn build_dom(scope: NodeScope, stream: port<Token>) -> Node {
loop { loop {
let token = stream.recv(); let token = stream.recv();
alt token { alt token {
parser::Eof { break; } parser::Eof { break; }
parser::StartOpeningTag(tag_name) { parser::StartOpeningTag(tag_name) {
#debug["starting tag %s", tag_name]; #debug["starting tag %s", tag_name];
let element_kind = build_element_kind(tag_name); let element_kind = build_element_kind(tag_name);
let new_node = scope.new_node(Element(ElementData(copy tag_name, element_kind))); let new_node = scope.new_node(Element(ElementData(copy tag_name, element_kind)));
scope.add_child(cur, new_node); scope.add_child(cur, new_node);
cur = new_node; cur = new_node;
} }
parser::Attr(key, value) { parser::Attr(key, value) {
#debug["attr: %? = %?", key, value]; #debug["attr: %? = %?", key, value];
link_up_attribute(scope, cur, copy key, copy value); link_up_attribute(scope, cur, copy key, copy value);
} }
parser::EndOpeningTag { parser::EndOpeningTag {
#debug("end opening tag"); #debug("end opening tag");
} }
parser::EndTag(_) | parser::SelfCloseTag {
// TODO: Assert that the closing tag has the right name. parser::EndTag(_) | parser::SelfCloseTag {
// TODO: Fail more gracefully (i.e. according to the HTML5 // TODO: Assert that the closing tag has the right name.
// spec) if we close more tags than we open. // TODO: Fail more gracefully (i.e. according to the HTML5
cur = scope.get_parent(cur).get(); // spec) if we close more tags than we open.
} cur = scope.get_parent(cur).get();
parser::Text(s) if !s.is_whitespace() { }
let new_node = scope.new_node(Text(copy s)); parser::Text(s) if !s.is_whitespace() {
scope.add_child(cur, new_node); let new_node = scope.new_node(Text(copy s));
} scope.add_child(cur, new_node);
parser::Text(_) { }
// FIXME: Whitespace should not be ignored. parser::Text(_) {
} // FIXME: Whitespace should not be ignored.
parser::Doctype { }
// TODO: Do something here... parser::Doctype {
} // TODO: Do something here...
}
} }
} }
ret cur; ret cur;