Skip to content
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
4 changes: 2 additions & 2 deletions ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum ComponentValue {
Number(NumericValue),
Percentage(NumericValue),
Dimension(NumericValue, ~str),
UnicodeRange { start: u32, end: u32 },
UnicodeRange(u32, u32), // (start, end) of range
WhiteSpace,
Colon, // :
Semicolon, // ;
Expand Down Expand Up @@ -121,7 +121,7 @@ pub enum ErrorReason {

impl ToStr for SyntaxError {
fn to_str(&self) -> ~str {
fmt!("%u:%u %?", self.location.line, self.location.column, self.reason)
format!("{}:{} {:?}", self.location.line, self.location.column, self.reason)
}
}

Expand Down
46 changes: 21 additions & 25 deletions color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::libc::c_float;
use std::ascii::StrAsciiExt;

use ast::*;
Expand All @@ -11,17 +10,14 @@ use self::color_data::{COLOR_KEYWORDS, COLOR_VALUES};
mod color_data;


// Try to match rust-azure’s AzFloat
pub type ColorFloat = c_float;


#[deriving(Clone, Eq)]
pub struct RGBA {
// All in 0..1
red: ColorFloat,
green: ColorFloat,
blue: ColorFloat,
alpha: ColorFloat,
// Use f32 to try and match rust-azure’s AzFloat
red: f32,
green: f32,
blue: f32,
alpha: f32,
}

#[deriving(Clone, Eq)]
Expand Down Expand Up @@ -70,9 +66,9 @@ fn parse_color_hash(value: &str) -> Option<Color> {
)
macro_rules! to_rgba(
($r: expr, $g: expr, $b: expr,) => {
Some(RGBA(RGBA { red: $r as ColorFloat / 255.,
green: $g as ColorFloat / 255.,
blue: $b as ColorFloat / 255.,
Some(RGBA(RGBA { red: $r as f32 / 255.,
green: $g as f32 / 255.,
blue: $b as f32 / 255.,
alpha: 1. }))
};
)
Expand Down Expand Up @@ -128,25 +124,25 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
});
)

let red: ColorFloat;
let green: ColorFloat;
let blue: ColorFloat;
let red: f32;
let green: f32;
let blue: f32;
if is_rgb {
// Either integers or percentages, but all the same type.
match iter.next() {
Some(&Number(ref v)) if v.int_value.is_some() => {
red = (v.value as ColorFloat / 255.) as ColorFloat;
red = (v.value / 255.) as f32;
expect_comma!();
green = (expect_integer!() / 255.) as ColorFloat;
green = (expect_integer!() / 255.) as f32;
expect_comma!();
blue = (expect_integer!() / 255.) as ColorFloat;
blue = (expect_integer!() / 255.) as f32;
}
Some(&Percentage(ref v)) => {
red = (v.value as ColorFloat / 100.) as ColorFloat;
red = (v.value / 100.) as f32;
expect_comma!();
green = (expect_percentage!() / 100.) as ColorFloat;
green = (expect_percentage!() / 100.) as f32;
expect_comma!();
blue = (expect_percentage!() / 100.) as ColorFloat;
blue = (expect_percentage!() / 100.) as f32;
}
_ => return None
};
Expand All @@ -171,14 +167,14 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
let m2 = if lightness <= 0.5 { lightness * (saturation + 1.) }
else { lightness + saturation - lightness * saturation };
let m1 = lightness * 2. - m2;
red = hue_to_rgb(m1, m2, hue + 1. / 3.) as ColorFloat;
green = hue_to_rgb(m1, m2, hue) as ColorFloat;
blue = hue_to_rgb(m1, m2, hue - 1. / 3.) as ColorFloat;
red = hue_to_rgb(m1, m2, hue + 1. / 3.) as f32;
green = hue_to_rgb(m1, m2, hue) as f32;
blue = hue_to_rgb(m1, m2, hue - 1. / 3.) as f32;
}

let alpha = if has_alpha {
expect_comma!();
(expect_number!()).max(&0.).min(&1.) as ColorFloat
(expect_number!()).max(&0.).min(&1.) as f32
} else {
1.
};
Expand Down
2 changes: 1 addition & 1 deletion lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#[link(name = "cssparser", vers = "0.1")];

#[feature(globs, macro_rules, struct_variant)];
#[feature(globs, macro_rules)];

extern mod extra;

Expand Down
4 changes: 2 additions & 2 deletions tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ impl ToJson for ComponentValue {
Dimension(ref value, ref unit)
=> JList(~[JString(~"dimension")] + numeric(value) + ~[unit.to_json()]),

UnicodeRange { start: s, end: e }
=> JList(~[JString(~"unicode-range"), s.to_json(), e.to_json()]),
UnicodeRange(start, end)
=> JList(~[JString(~"unicode-range"), start.to_json(), end.to_json()]),

WhiteSpace => JString(~" "),
Colon => JString(~":"),
Expand Down
2 changes: 1 addition & 1 deletion tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ fn consume_unicode_range(tokenizer: &mut Tokenizer) -> ComponentValue {
}
end = if hex.len() > 0 { num::from_str_radix(hex, 16).unwrap() } else { start }
}
UnicodeRange {start: start, end: end}
UnicodeRange(start, end)
}


Expand Down