Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Update to Rust 0.6 syntax. #1

Merged
merged 1 commit into from
Mar 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::float::round;
use core::libc::types::os::arch::c95::c_double;
use core::cmp::Eq;

#[deriving_eq]
#[deriving(Eq)]
pub struct Color {
red: u8,
green: u8,
Expand Down Expand Up @@ -96,7 +96,11 @@ pub mod parsing {
let only_colors = color.substr(4u, color.len() - 5u);

// split up r, g, and b
let cols = only_colors.split_char(',');
let mut cols = ~[];
for str::each_split_char(only_colors, ',') |s| {
cols.push(s);
};

if cols.len() != 3u { return fail_unrecognized(color); }

match (u8::from_str(cols[0]), u8::from_str(cols[1]),
Expand All @@ -112,7 +116,11 @@ pub mod parsing {
let only_vals = color.substr(5u, color.len() - 6u);

// split up r, g, and b
let cols = only_vals.split_char(',');
let mut cols = ~[];
for str::each_split_char(only_vals, ',') |s| {
cols.push(s);
};

if cols.len() != 4u { return fail_unrecognized(color); }

match (u8::from_str(cols[0]), u8::from_str(cols[1]),
Expand All @@ -128,7 +136,11 @@ pub mod parsing {
let only_vals = color.substr(4u, color.len() - 5u);

// split up h, s, and l
let vals = only_vals.split_char(',');
let mut vals = ~[];
for str::each_split_char(only_vals, ',') |s| {
vals.push(s);
};

if vals.len() != 3u { return fail_unrecognized(color); }

match (float::from_str(vals[0]), float::from_str(vals[1]),
Expand All @@ -143,7 +155,11 @@ pub mod parsing {
// Shave off the hsla( and the )
let only_vals = color.substr(5u, color.len() - 6u);

let vals = only_vals.split_char(',');
let mut vals = ~[];
for str::each_split_char(only_vals, ',') |s| {
vals.push(s);
};

if vals.len() != 4u { return fail_unrecognized(color); }

match (float::from_str(vals[0]), float::from_str(vals[1]),
Expand Down
12 changes: 6 additions & 6 deletions complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub struct CompleteSelectResults {
}

pub impl CompleteSelectResults {
static fn new_root(root: SelectResults) -> CompleteSelectResults {
fn new_root(root: SelectResults) -> CompleteSelectResults {
CompleteSelectResults {
inner: root
}
}

static fn new_from_parent(parent: &CompleteSelectResults,
child: SelectResults) -> CompleteSelectResults {
fn new_from_parent(parent: &CompleteSelectResults,
child: SelectResults) -> CompleteSelectResults {
let mut child = child;

// New lifetime
Expand Down Expand Up @@ -63,18 +63,18 @@ pub impl CompleteSelectResults {
}
}

fn computed_style(&self) -> CompleteStyle/&self {
fn computed_style(&self) -> CompleteStyle<'self> {
CompleteStyle {
inner: self.inner.computed_style()
}
}
}

pub struct CompleteStyle {
pub struct CompleteStyle<'self> {
inner: ComputedStyle<'self>
}

impl CompleteStyle<'self> {
impl<'self> CompleteStyle<'self> {

// CSS 2.1, Section 8 - Box model

Expand Down
2 changes: 1 addition & 1 deletion computed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::either::{Either, Left, Right};
use n;
use values::*;

pub struct ComputedStyle {
pub struct ComputedStyle<'self> {
inner: n::c::CssComputedStyle<'self>
}

Expand Down
14 changes: 7 additions & 7 deletions css.rc
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ mod test;

// Shortcuts to the netsurfcss types
pub mod n {
pub mod ll {
pub use p = netsurfcss::ll::properties;
pub use s = netsurfcss::ll::select;
pub use t = netsurfcss::ll::types;
pub use c = netsurfcss::ll::computed;
}

pub use p = netsurfcss::properties;
pub use s = netsurfcss::select;
pub use t = netsurfcss::types;
pub use c = netsurfcss::computed;
pub use v = netsurfcss::values;
pub use h = netsurfcss::hint;
pub use u = netsurfcss::util;

pub mod ll {
pub use p = netsurfcss::ll::properties;
pub use s = netsurfcss::ll::select;
pub use t = netsurfcss::ll::types;
pub use c = netsurfcss::ll::computed;
}
}
1 change: 0 additions & 1 deletion parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Constructs a list of css style rules from a token stream
// are not as expected

use util::DataStream;
use core::cell::Cell;
use netsurfcss::stylesheet::{CssStylesheet, CssStylesheetParams, CssStylesheetParamsVersion1, css_stylesheet_create};
use netsurfcss::types::CssLevel21;
use netsurfcss::CssResult;
Expand Down
10 changes: 5 additions & 5 deletions select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ encapsulates the cascade. Individual node styles can be requested with
the `select_style` method.
*/
pub impl SelectCtx {
static fn new() -> SelectCtx {
fn new() -> SelectCtx {
SelectCtx {
inner: n::s::css_select_ctx_create()
}
Expand Down Expand Up @@ -67,9 +67,9 @@ pub struct SelectResults {
inner: n::s::CssSelectResults
}

pub impl SelectResults {
pub impl<'self> SelectResults {
/** Retrieve the computed style of a single pseudo-element */
fn computed_style(&self) -> ComputedStyle/&self {
fn computed_style(&self) -> ComputedStyle<'self> {
ComputedStyle {
inner: self.inner.computed_style(n::s::CssPseudoElementNone)
}
Expand All @@ -95,8 +95,8 @@ struct SelectHandlerWrapper<N, H> {
inner: *H
}

priv impl<N, H: SelectHandler<N>> SelectHandlerWrapper<N, H> {
priv fn inner_ref(&self) -> &self/H {
priv impl<'self, N, H: SelectHandler<N>> SelectHandlerWrapper<N, H> {
priv fn inner_ref(&self) -> &'self H {
unsafe { &*self.inner }
}
}
Expand Down
2 changes: 1 addition & 1 deletion stylesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Stylesheet {
}

pub impl Stylesheet {
static fn new(url: Url, input: DataStream) -> Stylesheet {
fn new(url: Url, input: DataStream) -> Stylesheet {
Stylesheet {
inner: parse_stylesheet(url, input)
}
Expand Down
4 changes: 2 additions & 2 deletions test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct NodeData {
}

impl VoidPtrLike for TestNode {
static fn from_void_ptr(node: *libc::c_void) -> TestNode {
fn from_void_ptr(node: *libc::c_void) -> TestNode {
fail_unless!(node.is_not_null());
TestNode(unsafe {
let box = cast::reinterpret_cast(&node);
Expand All @@ -57,7 +57,7 @@ struct TestHandler {
}

impl TestHandler {
static fn new() -> TestHandler {
fn new() -> TestHandler {
TestHandler {
bogus: 0
}
Expand Down
14 changes: 7 additions & 7 deletions units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@
Units used by CSS
*/

#[deriving_eq]
#[deriving(Eq)]
pub enum Length {
Em(float), // normalized to 'em'
Px(float), // normalized to 'px'
Pt(float)
}

impl Length {
pure fn rel(self) -> float {
fn rel(self) -> float {
match self {
Em(x) => x,
_ => fail!(~"attempted to access relative unit of an absolute length")
}
}
pure fn abs(self) -> float {
fn abs(self) -> float {
match self {
Em(x) => x,
_ => fail!(~"attempted to access relative unit of an absolute length")
}
}
}

#[deriving_eq]
#[deriving(Eq)]
pub enum BoxSizing { // used by width, height, top, left, etc
BoxLength(Length),
BoxPercent(float),
BoxAuto
}

#[deriving_eq]
#[deriving(Eq)]
pub enum AbsoluteSize {
XXSmall,
XSmall,
Expand All @@ -42,13 +42,13 @@ pub enum AbsoluteSize {
XXLarge
}

#[deriving_eq]
#[deriving(Eq)]
pub enum RelativeSize {
Larger,
Smaller
}

#[deriving_eq]
#[deriving(Eq)]
pub enum GenericFontFamily {
Serif,
SansSerif,
Expand Down
4 changes: 1 addition & 3 deletions util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub type DataStream = @fn() -> Option<~[u8]>;

pub use netsurfcss::util::VoidPtrLike;


pub type DataStream = @fn() -> Option<~[u8]>;
Loading