Adapt to rust changes

This commit is contained in:
Tuncer Ayaz 2012-08-05 14:42:50 +02:00
parent 1a713b81bb
commit cb85521097
28 changed files with 198 additions and 198 deletions

View file

@ -115,10 +115,10 @@ class Content<S:Sink send copy> {
fn handle_msg(msg: either<ControlMsg,Event>) -> bool { fn handle_msg(msg: either<ControlMsg,Event>) -> bool {
alt msg { alt msg {
left(control_msg) { left(control_msg) {
ret self.handle_control_msg(control_msg); return self.handle_control_msg(control_msg);
} }
right(event) { right(event) {
ret self.handle_event(event); return self.handle_event(event);
} }
} }
} }
@ -157,7 +157,7 @@ class Content<S:Sink send copy> {
}); });
} }
ret true; return true;
} }
ExecuteMsg(url) { ExecuteMsg(url) {
@ -177,12 +177,12 @@ class Content<S:Sink send copy> {
}); });
} }
} }
ret true; return true;
} }
ExitMsg { ExitMsg {
self.layout.send(layout_task::ExitMsg); self.layout.send(layout_task::ExitMsg);
ret false; return false;
} }
} }
} }
@ -215,7 +215,7 @@ class Content<S:Sink send copy> {
self.relayout(*document); self.relayout(*document);
} }
} }
ret true; return true;
} }
} }
} }

View file

@ -41,7 +41,7 @@ class ElementData {
let mut i = 0u; let mut i = 0u;
while i < self.attrs.len() { while i < self.attrs.len() {
if attr_name == self.attrs[i].name { if attr_name == self.attrs[i].name {
ret some(copy self.attrs[i].value); return some(copy self.attrs[i].value);
} }
i += 1u; i += 1u;
} }

View file

@ -27,7 +27,7 @@ enum Element = int;
str::as_c_str("Not enough arguments", |s| { str::as_c_str("Not enough arguments", |s| {
JS_ReportError(cx, s); JS_ReportError(cx, s);
}); });
ret 0; return 0;
} }
let id; let id;
unsafe { unsafe {
@ -40,13 +40,13 @@ enum Element = int;
let elem = (*doc).getElementById(s); let elem = (*doc).getElementById(s);
} }
//XXX wrap result //XXX wrap result
ret 1; return 1;
} }
err(_) { err(_) {
str::as_c_str("???", |s| { str::as_c_str("???", |s| {
JS_ReportError(cx, s); JS_ReportError(cx, s);
}); });
ret 0; return 0;
} }
} }
}*/ }*/
@ -56,13 +56,13 @@ enum Element = int;
let uri = (*unwrap(JS_THIS_OBJECT(cx, vp))).payload.getDocumentURI(); let uri = (*unwrap(JS_THIS_OBJECT(cx, vp))).payload.getDocumentURI();
JS_SET_RVAL(cx, vp, domstring_to_jsval(cx, uri)); JS_SET_RVAL(cx, vp, domstring_to_jsval(cx, uri));
} }
ret 1; return 1;
}*/ }*/
extern fn getDocumentElement(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool unsafe { extern fn getDocumentElement(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool unsafe {
let node = (*unwrap(obj)).payload.root; let node = (*unwrap(obj)).payload.root;
*rval = RUST_OBJECT_TO_JSVAL(node::create(cx, node).ptr); *rval = RUST_OBJECT_TO_JSVAL(node::create(cx, node).ptr);
ret 1; return 1;
} }
unsafe fn unwrap(obj: *JSObject) -> *rust_box<Document> { unsafe fn unwrap(obj: *JSObject) -> *rust_box<Document> {

View file

@ -82,7 +82,7 @@ fn create(cx: *JSContext, node: Node) -> jsobj unsafe {
JS_SetReservedSlot(obj.ptr, 0, RUST_PRIVATE_TO_JSVAL(raw_ptr)); JS_SetReservedSlot(obj.ptr, 0, RUST_PRIVATE_TO_JSVAL(raw_ptr));
} }
ret obj; return obj;
} }
unsafe fn unwrap(obj: *JSObject) -> *rust_box<Node> { unsafe fn unwrap(obj: *JSObject) -> *rust_box<Node> {
@ -104,7 +104,7 @@ extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut js
} }
}); });
} }
ret 1; return 1;
} }
extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool { extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
@ -121,7 +121,7 @@ extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut j
} }
}); });
} }
ret 1; return 1;
} }
extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool { extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
@ -139,5 +139,5 @@ extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval
} }
}); });
} }
ret 1; return 1;
} }

View file

@ -37,13 +37,13 @@ fn jsval_to_str(cx: *JSContext, v: jsval) -> result<~str, ()> {
} else { } else {
jsstr = JS_ValueToString(cx, v); jsstr = JS_ValueToString(cx, v);
if jsstr.is_null() { if jsstr.is_null() {
ret err(()); return err(());
} }
} }
let len = 0; let len = 0;
let chars = JS_GetStringCharsZAndLength(cx, jsstr, ptr::addr_of(len)); let chars = JS_GetStringCharsZAndLength(cx, jsstr, ptr::addr_of(len));
ret if chars.is_null() { return if chars.is_null() {
err(()) err(())
} else { } else {
unsafe { unsafe {

View file

@ -138,7 +138,7 @@ impl ScopePrivate<T: copy send,A> for Scope<T,A> {
// take glue be tolerant of this. // take glue be tolerant of this.
*n = unsafe{*v}; *n = unsafe{*v};
ret unsafe::reinterpret_cast(n); return unsafe::reinterpret_cast(n);
} }
} }
@ -221,7 +221,7 @@ impl WriterMethods<T:copy send,A> for Scope<T,A> {
(*d).next_dirty = null_handle(); (*d).next_dirty = null_handle();
let h = _Handle(d); let h = _Handle(d);
push(self.d.free_list, h); push(self.d.free_list, h);
ret h; return h;
} }
} }

View file

@ -48,7 +48,7 @@ class Engine<S:Sink send copy> {
} else { } else {
self.content.send(ParseMsg(url)) self.content.send(ParseMsg(url))
} }
ret true; return true;
} }
ExitMsg(sender) { ExitMsg(sender) {
@ -63,7 +63,7 @@ class Engine<S:Sink send copy> {
self.resource_task.send(resource_task::Exit); self.resource_task.send(resource_task::Exit);
sender.send(()); sender.send(());
ret false; return false;
} }
} }
} }

View file

@ -99,7 +99,7 @@ fn do_draw(sender: pipes::chan<AzDrawTargetRef>,
let data = vec_from_buf(data, len); let data = vec_from_buf(data, len);
data_ch.send(data); data_ch.send(data);
ret CAIRO_STATUS_SUCCESS; return CAIRO_STATUS_SUCCESS;
} }
let closure = addr_of(data_ch); let closure = addr_of(data_ch);

View file

@ -58,7 +58,7 @@ class Appearance {
self.background_image = some(holder); self.background_image = some(holder);
} }
ret image; return image;
} }
} }
@ -115,7 +115,7 @@ class ImageHolder {
let im_arc = option::unwrap(temp); let im_arc = option::unwrap(temp);
self.image = some(clone(&im_arc)); self.image = some(clone(&im_arc));
ret ~im_arc; return ~im_arc;
} }
} }
@ -265,7 +265,7 @@ mod test {
push(r, copy root.bounds); push(r, copy root.bounds);
ret r; return r;
} }
#[test] #[test]

View file

@ -30,7 +30,7 @@ enum ctxt = {
}; };
fn create_context(parent_node: Node, parent_box: @Box) -> ctxt { fn create_context(parent_node: Node, parent_box: @Box) -> ctxt {
ret ctxt({ return ctxt({
parent_node: parent_node, parent_node: parent_node,
parent_box: parent_box, parent_box: parent_box,
mut anon_box: none mut anon_box: none
@ -194,7 +194,7 @@ impl box_builder_methods of box_builder_methods for Node {
// Nothing to do. // Nothing to do.
} }
} }
ret my_box; return my_box;
} }
} }

View file

@ -27,7 +27,7 @@ Builds a display list for a box and all its children
fn build_display_list(box : @Box) -> dl::display_list { fn build_display_list(box : @Box) -> dl::display_list {
let list = dvec(); let list = dvec();
build_display_list_from_origin(list, box, Point2D(au(0), au(0))); build_display_list_from_origin(list, box, Point2D(au(0), au(0)));
ret list; return list;
} }
#[doc=" #[doc="
@ -84,7 +84,7 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
item_type: dl::display_item_text(run.get()), item_type: dl::display_item_text(run.get()),
bounds: bounds bounds: bounds
})); }));
ret; return;
} }
_ { _ {
// Fall through // Fall through

View file

@ -16,24 +16,24 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
alt attr { alt attr {
Exists(name) { Exists(name) {
alt elmt.get_attr(name) { alt elmt.get_attr(name) {
some(_) { ret true; } some(_) { return true; }
none { ret false; } none { return false; }
} }
} }
Exact(name, val) { Exact(name, val) {
alt elmt.get_attr(name) { alt elmt.get_attr(name) {
some(value) { ret value == val; } some(value) { return value == val; }
none { ret false; } none { return false; }
} }
} }
Includes(name, val) { Includes(name, val) {
// Comply with css spec, if the specified attribute is empty // Comply with css spec, if the specified attribute is empty
// it cannot match. // it cannot match.
if val == ~"" { ret false; } if val == ~"" { return false; }
alt elmt.get_attr(name) { alt elmt.get_attr(name) {
some(value) { ret value.split_char(' ').contains(val); } some(value) { return value.split_char(' ').contains(val); }
none { ret false; } none { return false; }
} }
} }
StartsWith(name, val) { StartsWith(name, val) {
@ -41,14 +41,14 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
some(value) { some(value) {
//check that there is only one attribute value and it //check that there is only one attribute value and it
//starts with the perscribed value //starts with the perscribed value
if !value.starts_with(val) || value.contains(~" ") { ret false; } if !value.starts_with(val) || value.contains(~" ") { return false; }
// We match on either the exact value or value-foo // We match on either the exact value or value-foo
if value.len() == val.len() { ret true; } if value.len() == val.len() { return true; }
else { ret value.starts_with(val + ~"-"); } else { return value.starts_with(val + ~"-"); }
} }
none { none {
ret false; return false;
} }
} }
} }
@ -67,74 +67,74 @@ impl priv_matching_methods of priv_matching_methods for Node {
"] "]
fn matches_element(sel: ~Selector) -> bool { fn matches_element(sel: ~Selector) -> bool {
alt *sel { alt *sel {
Child(_, _) | Descendant(_, _) | Sibling(_, _) { ret false; } Child(_, _) | Descendant(_, _) | Sibling(_, _) { return false; }
Element(tag, attrs) { Element(tag, attrs) {
alt self.read(|n| copy *n.kind) { alt self.read(|n| copy *n.kind) {
base::Element(elmt) { base::Element(elmt) {
if !(tag == ~"*" || tag == elmt.tag_name) { if !(tag == ~"*" || tag == elmt.tag_name) {
ret false; return false;
} }
let mut i = 0u; let mut i = 0u;
while i < attrs.len() { while i < attrs.len() {
if !attrs_match(attrs[i], elmt) { ret false; } if !attrs_match(attrs[i], elmt) { return false; }
i += 1u; i += 1u;
} }
ret true; return true;
} }
Text(str) { /*fall through, currently unsupported*/ } Text(str) { /*fall through, currently unsupported*/ }
} }
} }
} }
ret false; //If we got this far it was because something was return false; //If we got this far it was because something was
//unsupported. //unsupported.
} }
#[doc = "Checks if a generic CSS selector matches a given HTML element"] #[doc = "Checks if a generic CSS selector matches a given HTML element"]
fn matches_selector(sel : ~Selector) -> bool { fn matches_selector(sel : ~Selector) -> bool {
alt *sel { alt *sel {
Element(str, atts) { ret self.matches_element(sel); } Element(str, atts) { return self.matches_element(sel); }
Child(sel1, sel2) { Child(sel1, sel2) {
alt self.read(|n| n.tree.parent) { alt self.read(|n| n.tree.parent) {
some(parent) { some(parent) {
ret self.matches_element(sel2) && return self.matches_element(sel2) &&
parent.matches_selector(sel1); parent.matches_selector(sel1);
} }
none { ret false; } none { return false; }
} }
} }
Descendant(sel1, sel2) { Descendant(sel1, sel2) {
if !self.matches_element(sel2) { if !self.matches_element(sel2) {
ret false; return false;
} }
//loop over all ancestors to check if they are the person //loop over all ancestors to check if they are the person
//we should be descended from. //we should be descended from.
let mut cur_parent = alt self.read(|n| n.tree.parent) { let mut cur_parent = alt self.read(|n| n.tree.parent) {
some(parent) { parent } some(parent) { parent }
none { ret false; } none { return false; }
}; };
loop { loop {
if cur_parent.matches_selector(sel1) { ret true; } if cur_parent.matches_selector(sel1) { return true; }
cur_parent = alt cur_parent.read(|n| n.tree.parent) { cur_parent = alt cur_parent.read(|n| n.tree.parent) {
some(parent) { parent } some(parent) { parent }
none { ret false; } none { return false; }
}; };
} }
} }
Sibling(sel1, sel2) { Sibling(sel1, sel2) {
if !self.matches_element(sel2) { ret false; } if !self.matches_element(sel2) { return false; }
// Loop over this node's previous siblings to see if they match. // Loop over this node's previous siblings to see if they match.
alt self.read(|n| n.tree.prev_sibling) { alt self.read(|n| n.tree.prev_sibling) {
some(sib) { some(sib) {
let mut cur_sib = sib; let mut cur_sib = sib;
loop { loop {
if cur_sib.matches_selector(sel1) { ret true; } if cur_sib.matches_selector(sel1) { return true; }
cur_sib = alt cur_sib.read(|n| n.tree.prev_sibling) { cur_sib = alt cur_sib.read(|n| n.tree.prev_sibling) {
some(sib) { sib } some(sib) { sib }
@ -150,7 +150,7 @@ impl priv_matching_methods of priv_matching_methods for Node {
some(sib) { some(sib) {
let mut cur_sib = sib; let mut cur_sib = sib;
loop { loop {
if cur_sib.matches_selector(sel1) { ret true; } if cur_sib.matches_selector(sel1) { return true; }
cur_sib = alt cur_sib.read(|n| n.tree.next_sibling) { cur_sib = alt cur_sib.read(|n| n.tree.next_sibling) {
some(sib) { sib } some(sib) { sib }
@ -161,7 +161,7 @@ impl priv_matching_methods of priv_matching_methods for Node {
none { } none { }
} }
ret false; return false;
} }
} }
} }
@ -227,7 +227,7 @@ mod test {
let elmt = ElementData(~"div", ~HTMLDivElement); let elmt = ElementData(~"div", ~HTMLDivElement);
let attr = ~Attr(name, val); let attr = ~Attr(name, val);
elmt.attrs.push(attr); elmt.attrs.push(attr);
ret scope.new_node(base::Element(elmt)); return scope.new_node(base::Element(elmt));
} }
#[test] #[test]

View file

@ -131,7 +131,7 @@ impl style_methods of style_methods for Node {
if !self.has_aux() { if !self.has_aux() {
fail ~"get_computed_style() called on a node without a style!"; fail ~"get_computed_style() called on a node without a style!";
} }
ret copy *self.aux(|x| copy x).specified_style; return copy *self.aux(|x| copy x).specified_style;
} }
#[doc=" #[doc="

View file

@ -22,13 +22,13 @@ type shared_box<T> = {
#[doc="Transform and @ into its underlying representation. The reference count stays constant."] #[doc="Transform and @ into its underlying representation. The reference count stays constant."]
fn unwrap_box(-b : @Box) -> *shared_box<Box> unsafe { fn unwrap_box(-b : @Box) -> *shared_box<Box> unsafe {
let new_box : *shared_box<Box> = unsafe::transmute(b); let new_box : *shared_box<Box> = unsafe::transmute(b);
ret new_box; return new_box;
} }
#[doc="Transform an underlying representation back to an @. The reference count stays constant."] #[doc="Transform an underlying representation back to an @. The reference count stays constant."]
fn rewrap_box(-b : *shared_box<Box>) -> @Box unsafe { fn rewrap_box(-b : *shared_box<Box>) -> @Box unsafe {
let new_box : @Box = unsafe::transmute(b); let new_box : @Box = unsafe::transmute(b);
ret new_box; return new_box;
} }
#[doc=" #[doc="
@ -89,7 +89,7 @@ fn traverse_helper(-root : @Box, -top_down : fn~(@Box), -bottom_up : fn~(@Box))
#[doc="A noneffectful function to be used if only one pass is required."] #[doc="A noneffectful function to be used if only one pass is required."]
fn nop(box : @Box) { fn nop(box : @Box) {
ret; return;
} }
#[doc=" #[doc="

View file

@ -50,7 +50,7 @@ impl parser_methods of parser_methods for TokenReader {
// Get the current element type // Get the current element type
let elmt_name = alt self.get() { let elmt_name = alt self.get() {
Element(tag) { copy tag } Element(tag) { copy tag }
Eof { ret none; } Eof { return none; }
_ { fail ~"Expected an element" } _ { fail ~"Expected an element" }
}; };
@ -65,13 +65,13 @@ impl parser_methods of parser_methods for TokenReader {
self.unget(tok); self.unget(tok);
break; break;
} }
Eof { ret none; } Eof { return none; }
Element(_) { fail ~"Unexpected second element without relation to first element"; } Element(_) { fail ~"Unexpected second element without relation to first element"; }
EndDescription { fail ~"Unexpected '}'"; } EndDescription { fail ~"Unexpected '}'"; }
Description(_, _) { fail ~"Unexpected description"; } Description(_, _) { fail ~"Unexpected description"; }
} }
} }
ret some(~style::Element(elmt_name, attr_list)); return some(~style::Element(elmt_name, attr_list));
} }
fn parse_selector() -> option<~[~Selector]> { fn parse_selector() -> option<~[~Selector]> {
@ -83,7 +83,7 @@ impl parser_methods of parser_methods for TokenReader {
alt self.parse_element() { alt self.parse_element() {
some(elmt) { cur_sel = copy elmt; } some(elmt) { cur_sel = copy elmt; }
none { ret none; } // we hit an eof in the middle of a rule none { return none; } // we hit an eof in the middle of a rule
} }
loop { loop {
@ -97,7 +97,7 @@ impl parser_methods of parser_methods for TokenReader {
let new_sel = copy elmt; let new_sel = copy elmt;
cur_sel <- ~style::Descendant(built_sel, new_sel) cur_sel <- ~style::Descendant(built_sel, new_sel)
} }
none { ret none; } none { return none; }
} }
} }
Child { Child {
@ -106,7 +106,7 @@ impl parser_methods of parser_methods for TokenReader {
let new_sel = copy elmt; let new_sel = copy elmt;
cur_sel <- ~style::Child(built_sel, new_sel) cur_sel <- ~style::Child(built_sel, new_sel)
} }
none { ret none; } none { return none; }
} }
} }
Sibling { Sibling {
@ -115,7 +115,7 @@ impl parser_methods of parser_methods for TokenReader {
let new_sel = copy elmt; let new_sel = copy elmt;
cur_sel <- ~style::Sibling(built_sel, new_sel) cur_sel <- ~style::Sibling(built_sel, new_sel)
} }
none { ret none; } none { return none; }
} }
} }
StartDescription { StartDescription {
@ -131,7 +131,7 @@ impl parser_methods of parser_methods for TokenReader {
Attr(_) | EndDescription | Element(_) | Description(_, _) { Attr(_) | EndDescription | Element(_) | Description(_, _) {
fail #fmt["Unexpected token %? in elements", tok]; fail #fmt["Unexpected token %? in elements", tok];
} }
Eof { ret none; } Eof { return none; }
} }
} }
@ -145,7 +145,7 @@ impl parser_methods of parser_methods for TokenReader {
} }
} }
ret some(sel_list); return some(sel_list);
} }
fn parse_description() -> option<~[StyleDeclaration]> { fn parse_description() -> option<~[StyleDeclaration]> {
@ -169,20 +169,20 @@ impl parser_methods of parser_methods for TokenReader {
}; };
desc.map(|res| push(desc_list, res)); desc.map(|res| push(desc_list, res));
} }
Eof { ret none; } Eof { return none; }
StartDescription | Descendant | Child | Sibling | Comma | Element(_) | Attr(_) { StartDescription | Descendant | Child | Sibling | Comma | Element(_) | Attr(_) {
fail #fmt["Unexpected token %? in description", tok]; fail #fmt["Unexpected token %? in description", tok];
} }
} }
} }
ret some(desc_list); return some(desc_list);
} }
fn parse_rule() -> option<~style::Rule> { fn parse_rule() -> option<~style::Rule> {
let sel_list = alt self.parse_selector() { let sel_list = alt self.parse_selector() {
some(list){ copy list } some(list){ copy list }
none { ret none; } none { return none; }
}; };
#debug("sel_list: %?", sel_list); #debug("sel_list: %?", sel_list);
@ -190,12 +190,12 @@ impl parser_methods of parser_methods for TokenReader {
// Get the description to be applied to the selector // Get the description to be applied to the selector
let desc_list = alt self.parse_description() { let desc_list = alt self.parse_description() {
some(list) { copy list } some(list) { copy list }
none { ret none; } none { return none; }
}; };
#debug("desc_list: %?", desc_list); #debug("desc_list: %?", desc_list);
ret some(~(sel_list, desc_list)); return some(~(sel_list, desc_list));
} }
} }
@ -210,5 +210,5 @@ fn build_stylesheet(+stream : pipes::port<Token>) -> ~[~style::Rule] {
} }
} }
ret rule_list; return rule_list;
} }

View file

@ -51,7 +51,7 @@ impl css_methods of css_methods for CssLexer {
let mut ch: u8; let mut ch: u8;
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c; } CoeChar(c) { ch = c; }
CoeEof { ret Eof; } CoeEof { return Eof; }
} }
let token = alt self.parser_state { let token = alt self.parser_state {
@ -62,7 +62,7 @@ impl css_methods of css_methods for CssLexer {
}; };
#debug["token=%?", token]; #debug["token=%?", token];
ret token; return token;
} }
fn parse_css_relation(c : u8) -> Token { fn parse_css_relation(c : u8) -> Token {
@ -78,7 +78,7 @@ impl css_methods of css_methods for CssLexer {
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
ret token; return token;
} }
fn parse_css_element(c : u8) -> Token { fn parse_css_element(c : u8) -> Token {
@ -89,10 +89,10 @@ impl css_methods of css_methods for CssLexer {
if c == '.' as u8 || c == '#' as u8 { if c == '.' as u8 || c == '#' as u8 {
self.parser_state = CssAttribute; self.parser_state = CssAttribute;
self.input_state.unget(c); self.input_state.unget(c);
ret Element(~"*"); return Element(~"*");
} else if c == '*' as u8 { } else if c == '*' as u8 {
self.parser_state = CssAttribute; self.parser_state = CssAttribute;
ret Element(~"*"); return Element(~"*");
} }
self.input_state.unget(c); self.input_state.unget(c);
@ -100,7 +100,7 @@ impl css_methods of css_methods for CssLexer {
self.parser_state = CssAttribute; self.parser_state = CssAttribute;
ret Element(element); return Element(element);
} }
fn parse_css_attribute(c : u8) -> Token { fn parse_css_attribute(c : u8) -> Token {
@ -117,12 +117,12 @@ impl css_methods of css_methods for CssLexer {
CoeEof { fail ~"File ended before description of style" } CoeEof { fail ~"File ended before description of style" }
} }
ret self.parse_css_relation(ch); return self.parse_css_relation(ch);
} }
alt ch { alt ch {
'.' as u8 { ret Attr(style::Includes(~"class", self.input_state.parse_ident())); } '.' as u8 { return Attr(style::Includes(~"class", self.input_state.parse_ident())); }
'#' as u8 { ret Attr(style::Includes(~"id", self.input_state.parse_ident())); } '#' as u8 { return Attr(style::Includes(~"id", self.input_state.parse_ident())); }
'[' as u8 { '[' as u8 {
let attr_name = self.input_state.parse_ident(); let attr_name = self.input_state.parse_ident();
@ -132,21 +132,21 @@ impl css_methods of css_methods for CssLexer {
} }
if ch == ']' as u8 { if ch == ']' as u8 {
ret Attr(style::Exists(attr_name)); return Attr(style::Exists(attr_name));
} else if ch == '=' as u8 { } else if ch == '=' as u8 {
let attr_val = self.input_state.parse_ident(); let attr_val = self.input_state.parse_ident();
self.input_state.expect(']' as u8); self.input_state.expect(']' as u8);
ret Attr(style::Exact(attr_name, attr_val)); return Attr(style::Exact(attr_name, attr_val));
} else if ch == '~' as u8 { } else if ch == '~' as u8 {
self.input_state.expect('=' as u8); self.input_state.expect('=' as u8);
let attr_val = self.input_state.parse_ident(); let attr_val = self.input_state.parse_ident();
self.input_state.expect(']' as u8); self.input_state.expect(']' as u8);
ret Attr(style::Includes(attr_name, attr_val)); return Attr(style::Includes(attr_name, attr_val));
} else if ch == '|' as u8 { } else if ch == '|' as u8 {
self.input_state.expect('=' as u8); self.input_state.expect('=' as u8);
let attr_val = self.input_state.parse_ident(); let attr_val = self.input_state.parse_ident();
self.input_state.expect(']' as u8); self.input_state.expect(']' as u8);
ret Attr(style::StartsWith(attr_name, attr_val)); return Attr(style::StartsWith(attr_name, attr_val));
} }
fail #fmt("Unexpected symbol %c in attribute", ch as char); fail #fmt("Unexpected symbol %c in attribute", ch as char);
@ -161,7 +161,7 @@ impl css_methods of css_methods for CssLexer {
if ch == '}' as u8 { if ch == '}' as u8 {
self.parser_state = CssElement; self.parser_state = CssElement;
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
ret EndDescription; return EndDescription;
} else if ch.is_whitespace() { } else if ch.is_whitespace() {
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
@ -223,12 +223,12 @@ impl css_methods of css_methods for CssLexer {
} }
} }
ret Description(from_bytes(desc_name), from_bytes(desc_val)); return Description(from_bytes(desc_name), from_bytes(desc_val));
} }
} }
fn parser(input_port: comm::port<ProgressMsg>, state : ParserState) -> CssLexer { fn parser(input_port: comm::port<ProgressMsg>, state : ParserState) -> CssLexer {
ret { return {
input_state: { input_state: {
mut lookahead: none, mut lookahead: none,
mut buffer: ~[], mut buffer: ~[],
@ -266,7 +266,7 @@ fn spawn_css_lexer_from_string(-content : ~str) -> pipes::port<Token> {
lex_css_from_bytes(input_port, result_chan); lex_css_from_bytes(input_port, result_chan);
} }
ret result_port; return result_port;
} }
#[warn(no_non_implicitly_copyable_typarams)] #[warn(no_non_implicitly_copyable_typarams)]
@ -281,5 +281,5 @@ fn spawn_css_lexer_task(-url: url, resource_task: ResourceTask) -> pipes::port<T
lex_css_from_bytes(input_port, result_chan); lex_css_from_bytes(input_port, result_chan);
}); });
ret result_port; return result_port;
} }

View file

@ -268,5 +268,5 @@ fn build_dom(scope: NodeScope, stream: comm::port<Token>, url: url,
style_chan.send(Exit); style_chan.send(Exit);
js_chan.send(js_exit); js_chan.send(js_exit);
ret (cur_node, style_port, js_port); return (cur_node, style_port, js_port);
} }

View file

@ -40,7 +40,7 @@ impl html_methods of html_methods for HtmlLexer {
let mut ch: u8; let mut ch: u8;
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c; } CoeChar(c) { ch = c; }
CoeEof { ret Eof; } CoeEof { return Eof; }
} }
let token = alt self.parser_state { let token = alt self.parser_state {
NormalHtml { self.parse_in_normal_state(ch) } NormalHtml { self.parse_in_normal_state(ch) }
@ -48,7 +48,7 @@ impl html_methods of html_methods for HtmlLexer {
}; };
#debug["token=%?", token]; #debug["token=%?", token];
ret token; return token;
} }
fn parse_in_normal_state(c: u8) -> Token { fn parse_in_normal_state(c: u8) -> Token {
@ -66,13 +66,13 @@ impl html_methods of html_methods for HtmlLexer {
self.input_state.expect_ident(~"html"); self.input_state.expect_ident(~"html");
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
self.input_state.expect('>' as u8); self.input_state.expect('>' as u8);
ret Doctype; return Doctype;
} }
if ch == ('/' as u8) { if ch == ('/' as u8) {
let ident = self.input_state.parse_ident(); let ident = self.input_state.parse_ident();
self.input_state.expect('>' as u8); self.input_state.expect('>' as u8);
ret EndTag(ident); return EndTag(ident);
} }
self.input_state.unget(ch); self.input_state.unget(ch);
@ -82,7 +82,7 @@ impl html_methods of html_methods for HtmlLexer {
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
self.parser_state = TagHtml; self.parser_state = TagHtml;
ret StartOpeningTag(ident); return StartOpeningTag(ident);
} }
// Make a text node. // Make a text node.
@ -92,11 +92,11 @@ impl html_methods of html_methods for HtmlLexer {
CoeChar(c) { CoeChar(c) {
if c == ('<' as u8) { if c == ('<' as u8) {
self.input_state.unget(c); self.input_state.unget(c);
ret Text(from_bytes(s)); return Text(from_bytes(s));
} }
push(s, c); push(s, c);
} }
CoeEof { ret Text(from_bytes(s)); } CoeEof { return Text(from_bytes(s)); }
} }
} }
} }
@ -106,7 +106,7 @@ impl html_methods of html_methods for HtmlLexer {
if ch == ('>' as u8) { if ch == ('>' as u8) {
self.parser_state = NormalHtml; self.parser_state = NormalHtml;
ret EndOpeningTag; return EndOpeningTag;
} }
if ch == ('/' as u8) { if ch == ('/' as u8) {
@ -114,7 +114,7 @@ impl html_methods of html_methods for HtmlLexer {
CoeChar(c) { CoeChar(c) {
if c == ('>' as u8) { if c == ('>' as u8) {
self.parser_state = NormalHtml; self.parser_state = NormalHtml;
ret SelfCloseTag; return SelfCloseTag;
} else { } else {
#warn["/ not followed by > in a tag"]; #warn["/ not followed by > in a tag"];
} }
@ -139,7 +139,7 @@ impl html_methods of html_methods for HtmlLexer {
} }
CoeEof { CoeEof {
let name = from_bytes(attribute_name); let name = from_bytes(attribute_name);
ret Attr(copy name, name); return Attr(copy name, name);
} }
} }
} }
@ -154,7 +154,7 @@ impl html_methods of html_methods for HtmlLexer {
push(attribute_value, c); push(attribute_value, c);
} }
CoeEof { CoeEof {
ret Attr(from_bytes(attribute_name), from_bytes(attribute_value)); return Attr(from_bytes(attribute_name), from_bytes(attribute_value));
} }
} }
} }
@ -162,12 +162,12 @@ impl html_methods of html_methods for HtmlLexer {
// Eat whitespacpe. // Eat whitespacpe.
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
ret Attr(from_bytes(attribute_name), from_bytes(attribute_value)); return Attr(from_bytes(attribute_name), from_bytes(attribute_value));
} }
} }
fn lexer(+input_port: port<resource_task::ProgressMsg>, state : ParseState) -> HtmlLexer { fn lexer(+input_port: port<resource_task::ProgressMsg>, state : ParseState) -> HtmlLexer {
ret { return {
input_state: { input_state: {
mut lookahead: none, mut lookahead: none,
mut buffer: ~[], mut buffer: ~[],
@ -197,5 +197,5 @@ fn spawn_html_lexer_task(-url: url, resource_task: ResourceTask) -> port<Token>
} }
}); });
ret html_port; return html_port;
} }

View file

@ -25,11 +25,11 @@ trait u8_methods {
impl u8_methods of u8_methods for u8 { impl u8_methods of u8_methods for u8 {
fn is_whitespace() -> bool { fn is_whitespace() -> bool {
ret self == ' ' as u8 || self == '\n' as u8 || self == '\t' as u8; return self == ' ' as u8 || self == '\n' as u8 || self == '\t' as u8;
} }
fn is_alpha() -> bool { fn is_alpha() -> bool {
ret (self >= ('A' as u8) && self <= ('Z' as u8)) || return (self >= ('A' as u8) && self <= ('Z' as u8)) ||
(self >= ('a' as u8) && self <= ('z' as u8)); (self >= ('a' as u8) && self <= ('z' as u8));
} }
} }
@ -50,7 +50,7 @@ impl util_methods of util_methods for InputState {
some(coe) { some(coe) {
let rv = coe; let rv = coe;
self.lookahead = none; self.lookahead = none;
ret rv; return rv;
} }
none { none {
/* fall through */ /* fall through */
@ -60,21 +60,21 @@ impl util_methods of util_methods for InputState {
// FIXME: Lots of copies here // FIXME: Lots of copies here
if self.buffer.len() > 0 { if self.buffer.len() > 0 {
ret CoeChar(vec::shift(self.buffer)); return CoeChar(vec::shift(self.buffer));
} }
if self.eof { if self.eof {
ret CoeEof; return CoeEof;
} }
alt self.input_port.recv() { alt self.input_port.recv() {
Payload(data) { Payload(data) {
self.buffer = data; self.buffer = data;
ret CoeChar(vec::shift(self.buffer)); return CoeChar(vec::shift(self.buffer));
} }
Done(*) { Done(*) {
self.eof = true; self.eof = true;
ret CoeEof; return CoeEof;
} }
} }
} }
@ -112,7 +112,7 @@ impl util_methods of util_methods for InputState {
} }
} }
} }
ret str::from_bytes(result); return str::from_bytes(result);
} }
fn expect_ident(expected: ~str) { fn expect_ident(expected: ~str) {
@ -128,11 +128,11 @@ impl util_methods of util_methods for InputState {
CoeChar(c) { CoeChar(c) {
if !c.is_whitespace() { if !c.is_whitespace() {
self.unget(c); self.unget(c);
ret; return;
} }
} }
CoeEof { CoeEof {
ret; return;
} }
} }
} }

View file

@ -95,10 +95,10 @@ class ResourceManager {
for self.loaders.each |scheme_loader| { for self.loaders.each |scheme_loader| {
let (scheme, loader_factory) = scheme_loader; let (scheme, loader_factory) = scheme_loader;
if scheme == url.scheme { if scheme == url.scheme {
ret some(loader_factory); return some(loader_factory);
} }
} }
ret none; return none;
} }
} }

View file

@ -62,7 +62,7 @@ class Font {
) )
}); });
ret if status == CAIRO_STATUS_SUCCESS { return if status == CAIRO_STATUS_SUCCESS {
// This might not be true, but at least we'll know if it isn't // This might not be true, but at least we'll know if it isn't
assert num_glyphs == 1 as c_int; assert num_glyphs == 1 as c_int;
@ -107,7 +107,7 @@ class Font {
#debug("x_advance: %?", extents.x_advance); #debug("x_advance: %?", extents.x_advance);
#debug("y_advance: %?", extents.y_advance); #debug("y_advance: %?", extents.y_advance);
ret extents.x_advance as int; return extents.x_advance as int;
} }
status { status {
import str::unsafe::from_c_str; import str::unsafe::from_c_str;
@ -266,7 +266,7 @@ fn create_test_font() -> @Font {
import font_library::FontLibrary; import font_library::FontLibrary;
let flib = FontLibrary(); let flib = FontLibrary();
ret flib.get_test_font(); return flib.get_test_font();
} }
fn test_font_bin() -> ~[u8] { #include_bin("JosefinSans-SemiBold.ttf") } fn test_font_bin() -> ~[u8] { #include_bin("JosefinSans-SemiBold.ttf") }

View file

@ -9,7 +9,7 @@ class FontLibrary {
fn get_font() -> @Font { fn get_font() -> @Font {
let f = Font(font::test_font_bin()); let f = Font(font::test_font_bin());
ret @f; return @f;
} }
fn get_test_font() -> @Font { fn get_test_font() -> @Font {

View file

@ -35,7 +35,7 @@ class FreeTypeNativeFont/& {
fn glyph_index(codepoint: char) -> option<GlyphIndex> { fn glyph_index(codepoint: char) -> option<GlyphIndex> {
assert self.face.is_not_null(); assert self.face.is_not_null();
let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong); let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong);
ret if idx != 0 as FT_UInt { return if idx != 0 as FT_UInt {
some(idx as GlyphIndex) some(idx as GlyphIndex)
} else { } else {
#warn("Invalid codepoint: %?", codepoint); #warn("Invalid codepoint: %?", codepoint);
@ -56,11 +56,11 @@ class FreeTypeNativeFont/& {
#debug("h_advance for %? is %?", glyph, advance); #debug("h_advance for %? is %?", glyph, advance);
// FIXME: Dividing by 64 converts to pixels, which // FIXME: Dividing by 64 converts to pixels, which
// is not the unit we should be using // is not the unit we should be using
ret some((advance / 64) as int); return some((advance / 64) as int);
} }
} else { } else {
#warn("Unable to load glyph %?. reason: %?", glyph, res); #warn("Unable to load glyph %?. reason: %?", glyph, res);
ret none; return none;
} }
} }
} }
@ -68,7 +68,7 @@ class FreeTypeNativeFont/& {
fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> { fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> {
assert lib.is_not_null(); assert lib.is_not_null();
let face: FT_Face = null(); let face: FT_Face = null();
ret vec_as_buf(*buf, |cbuf, len| { return vec_as_buf(*buf, |cbuf, len| {
if FT_New_Memory_Face(lib, cbuf, (*buf).len() as FT_Long, if FT_New_Memory_Face(lib, cbuf, (*buf).len() as FT_Long,
0 as FT_Long, addr_of(face)).succeeded() { 0 as FT_Long, addr_of(face)).succeeded() {
// FIXME: These values are placeholders // FIXME: These values are placeholders

View file

@ -62,7 +62,7 @@ fn create(buf: ~[u8]) -> result<QuartzNativeFont, ()> {
// FIXME: Error handling // FIXME: Error handling
assert cgfont.is_not_null(); assert cgfont.is_not_null();
ret ok(QuartzNativeFont(fontprov, cgfont)); return ok(QuartzNativeFont(fontprov, cgfont));
} }
fn with_test_native_font(f: fn@(nf: &NativeFont)) { fn with_test_native_font(f: fn@(nf: &NativeFont)) {

View file

@ -98,7 +98,7 @@ fn shape_text(font: &Font, text: ~str) -> ~[Glyph] unsafe {
hb_face_destroy(hbface); hb_face_destroy(hbface);
hb_blob_destroy(face_blob); hb_blob_destroy(face_blob);
ret glyphs; return glyphs;
} }
extern fn glyph_func(_font: *hb_font_t, extern fn glyph_func(_font: *hb_font_t,
@ -111,7 +111,7 @@ extern fn glyph_func(_font: *hb_font_t,
let font: *Font = reinterpret_cast(font_data); let font: *Font = reinterpret_cast(font_data);
assert font.is_not_null(); assert font.is_not_null();
ret alt (*font).glyph_idx(unicode as char) { return alt (*font).glyph_idx(unicode as char) {
some(g) { some(g) {
*glyph = g as hb_codepoint_t; *glyph = g as hb_codepoint_t;
true true
@ -131,7 +131,7 @@ extern fn glyph_h_advance_func(_font: *hb_font_t,
let h_advance = (*font).glyph_h_advance(glyph as uint); let h_advance = (*font).glyph_h_advance(glyph as uint);
#debug("h_advance for codepoint %? is %?", glyph, h_advance); #debug("h_advance for codepoint %? is %?", glyph, h_advance);
ret h_advance as hb_position_t; return h_advance as hb_position_t;
} }
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> GlyphPos { fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> GlyphPos {

View file

@ -24,7 +24,7 @@ class TextRun {
Point2D(cur.x.add(glyph.pos.offset.x).add(glyph.pos.advance.x), Point2D(cur.x.add(glyph.pos.offset.x).add(glyph.pos.advance.x),
cur.y.add(glyph.pos.offset.y).add(glyph.pos.advance.y)) cur.y.add(glyph.pos.offset.y).add(glyph.pos.advance.y))
}); });
ret Size2D(pen_end.x, pen_end.y); return Size2D(pen_end.x, pen_end.y);
} }
} }

View file

@ -13,7 +13,7 @@ enum Color = {red : u8, green : u8, blue : u8, alpha : float};
impl Color of eq for Color { impl Color of eq for Color {
pure fn eq(&&other: Color) -> bool { pure fn eq(&&other: Color) -> bool {
ret self.red == other.red && self.green == other.green && self.blue == other.blue && return self.red == other.red && self.green == other.green && self.blue == other.blue &&
self.alpha == other.alpha; self.alpha == other.alpha;
} }
} }
@ -23,7 +23,7 @@ fn rgba(r : u8, g : u8, b : u8, a : float) -> Color {
} }
fn rgb(r : u8, g : u8, b : u8) -> Color { fn rgb(r : u8, g : u8, b : u8) -> Color {
ret rgba(r, g, b, 1.0); return rgba(r, g, b, 1.0);
} }
fn hsla(h : float, s : float, l : float, a : float) -> Color { fn hsla(h : float, s : float, l : float, a : float) -> Color {
@ -37,10 +37,10 @@ fn hsla(h : float, s : float, l : float, a : float) -> Color {
let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h }; let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h };
alt h { alt h {
0.0 to 1.0/6.0 { ret m1 + (m2 - m1)*h*6.0; } 0.0 to 1.0/6.0 { return m1 + (m2 - m1)*h*6.0; }
1.0/6.0 to 1.0/2.0 { ret m2; } 1.0/6.0 to 1.0/2.0 { return m2; }
1.0/2.0 to 2.0/3.0 { ret m1 + (m2 - m1)*(4.0 - 6.0*h); } 1.0/2.0 to 2.0/3.0 { return m1 + (m2 - m1)*(4.0 - 6.0*h); }
2.0/3.0 to 1.0 { ret m1; } 2.0/3.0 to 1.0 { return m1; }
_ { fail ~"unexpected hue value"; } _ { fail ~"unexpected hue value"; }
} }
} }
@ -49,11 +49,11 @@ fn hsla(h : float, s : float, l : float, a : float) -> Color {
let g = round(255.0*hue_to_rgb(m1, m2, h) as c_double); let g = round(255.0*hue_to_rgb(m1, m2, h) as c_double);
let b = round(255.0*hue_to_rgb(m1, m2, h - 1.0/3.0) as c_double); let b = round(255.0*hue_to_rgb(m1, m2, h - 1.0/3.0) as c_double);
ret rgba(r as u8, g as u8, b as u8, a); return rgba(r as u8, g as u8, b as u8, a);
} }
fn hsl(h : float, s : float, l : float) -> Color { fn hsl(h : float, s : float, l : float) -> Color {
ret hsla(h, s, l, 1.0); return hsla(h, s, l, 1.0);
} }
impl methods for Color { impl methods for Color {
@ -68,7 +68,7 @@ mod parsing {
fn fail_unrecognized(col : ~str) -> option<Color> { fn fail_unrecognized(col : ~str) -> option<Color> {
#warn["Unrecognized color %s", col]; #warn["Unrecognized color %s", col];
ret none; return none;
} }
#[doc="Match an exact color keyword."] #[doc="Match an exact color keyword."]
@ -91,10 +91,10 @@ mod parsing {
~"blue" { blue() } ~"blue" { blue() }
~"teal" { teal() } ~"teal" { teal() }
~"aqua" { aqua() } ~"aqua" { aqua() }
_ { ret fail_unrecognized(color) } _ { return fail_unrecognized(color) }
}; };
ret some(col); return some(col);
} }
#[doc="Parses a color specification in the form rgb(foo,bar,baz)"] #[doc="Parses a color specification in the form rgb(foo,bar,baz)"]
@ -104,7 +104,7 @@ mod parsing {
// split up r, g, and b // split up r, g, and b
let cols = only_colors.split_char(','); let cols = only_colors.split_char(',');
if cols.len() != 3u { ret fail_unrecognized(color); } if cols.len() != 3u { return fail_unrecognized(color); }
alt (u8::from_str(cols[0]), u8::from_str(cols[1]), alt (u8::from_str(cols[0]), u8::from_str(cols[1]),
u8::from_str(cols[2])) { u8::from_str(cols[2])) {
@ -120,7 +120,7 @@ mod parsing {
// split up r, g, and b // split up r, g, and b
let cols = only_vals.split_char(','); let cols = only_vals.split_char(',');
if cols.len() != 4u { ret fail_unrecognized(color); } if cols.len() != 4u { return fail_unrecognized(color); }
alt (u8::from_str(cols[0]), u8::from_str(cols[1]), alt (u8::from_str(cols[0]), u8::from_str(cols[1]),
u8::from_str(cols[2]), float::from_str(cols[3])) { u8::from_str(cols[2]), float::from_str(cols[3])) {
@ -136,7 +136,7 @@ mod parsing {
// split up h, s, and l // split up h, s, and l
let vals = only_vals.split_char(','); let vals = only_vals.split_char(',');
if vals.len() != 3u { ret fail_unrecognized(color); } if vals.len() != 3u { return fail_unrecognized(color); }
alt (float::from_str(vals[0]), float::from_str(vals[1]), alt (float::from_str(vals[0]), float::from_str(vals[1]),
float::from_str(vals[2])) { float::from_str(vals[2])) {
@ -151,7 +151,7 @@ mod parsing {
let only_vals = color.substr(5u, color.len() - 6u); let only_vals = color.substr(5u, color.len() - 6u);
let vals = only_vals.split_char(','); let vals = only_vals.split_char(',');
if vals.len() != 4u { ret fail_unrecognized(color); } if vals.len() != 4u { return fail_unrecognized(color); }
alt (float::from_str(vals[0]), float::from_str(vals[1]), alt (float::from_str(vals[0]), float::from_str(vals[1]),
float::from_str(vals[2]), float::from_str(vals[3])) { float::from_str(vals[2]), float::from_str(vals[3])) {

View file

@ -22,9 +22,9 @@ fn each_child<T:copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
let mut p = ops.with_tree_fields(node, |f| f.first_child); let mut p = ops.with_tree_fields(node, |f| f.first_child);
loop { loop {
alt copy p { alt copy p {
none { ret; } none { return; }
some(c) { some(c) {
if !f(c) { ret; } if !f(c) { return; }
p = ops.with_tree_fields(c, |f| f.next_sibling); p = ops.with_tree_fields(c, |f| f.next_sibling);
} }
} }
@ -109,7 +109,7 @@ mod test {
add_child(dtree, p, c); add_child(dtree, p, c);
} }
ret {p: p, children: children}; return {p: p, children: children};
} }
#[test] #[test]