Skip to content

Commit f494977

Browse files
committed
Merge pull request #22 from SimonSapin/master
Upgrade rust and some clean-ups. r=metajack
2 parents 0978ae5 + ce01ee2 commit f494977

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum ComponentValue {
3636
Number(NumericValue),
3737
Percentage(NumericValue),
3838
Dimension(NumericValue, ~str),
39-
UnicodeRange { start: u32, end: u32 },
39+
UnicodeRange(u32, u32), // (start, end) of range
4040
WhiteSpace,
4141
Colon, // :
4242
Semicolon, // ;
@@ -121,7 +121,7 @@ pub enum ErrorReason {
121121

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

color.rs

+21-25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use std::libc::c_float;
65
use std::ascii::StrAsciiExt;
76

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

1312

14-
// Try to match rust-azure’s AzFloat
15-
pub type ColorFloat = c_float;
16-
17-
1813
#[deriving(Clone, Eq)]
1914
pub struct RGBA {
2015
// All in 0..1
21-
red: ColorFloat,
22-
green: ColorFloat,
23-
blue: ColorFloat,
24-
alpha: ColorFloat,
16+
// Use f32 to try and match rust-azure’s AzFloat
17+
red: f32,
18+
green: f32,
19+
blue: f32,
20+
alpha: f32,
2521
}
2622

2723
#[deriving(Clone, Eq)]
@@ -70,9 +66,9 @@ fn parse_color_hash(value: &str) -> Option<Color> {
7066
)
7167
macro_rules! to_rgba(
7268
($r: expr, $g: expr, $b: expr,) => {
73-
Some(RGBA(RGBA { red: $r as ColorFloat / 255.,
74-
green: $g as ColorFloat / 255.,
75-
blue: $b as ColorFloat / 255.,
69+
Some(RGBA(RGBA { red: $r as f32 / 255.,
70+
green: $g as f32 / 255.,
71+
blue: $b as f32 / 255.,
7672
alpha: 1. }))
7773
};
7874
)
@@ -128,25 +124,25 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
128124
});
129125
)
130126

131-
let red: ColorFloat;
132-
let green: ColorFloat;
133-
let blue: ColorFloat;
127+
let red: f32;
128+
let green: f32;
129+
let blue: f32;
134130
if is_rgb {
135131
// Either integers or percentages, but all the same type.
136132
match iter.next() {
137133
Some(&Number(ref v)) if v.int_value.is_some() => {
138-
red = (v.value as ColorFloat / 255.) as ColorFloat;
134+
red = (v.value / 255.) as f32;
139135
expect_comma!();
140-
green = (expect_integer!() / 255.) as ColorFloat;
136+
green = (expect_integer!() / 255.) as f32;
141137
expect_comma!();
142-
blue = (expect_integer!() / 255.) as ColorFloat;
138+
blue = (expect_integer!() / 255.) as f32;
143139
}
144140
Some(&Percentage(ref v)) => {
145-
red = (v.value as ColorFloat / 100.) as ColorFloat;
141+
red = (v.value / 100.) as f32;
146142
expect_comma!();
147-
green = (expect_percentage!() / 100.) as ColorFloat;
143+
green = (expect_percentage!() / 100.) as f32;
148144
expect_comma!();
149-
blue = (expect_percentage!() / 100.) as ColorFloat;
145+
blue = (expect_percentage!() / 100.) as f32;
150146
}
151147
_ => return None
152148
};
@@ -171,14 +167,14 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
171167
let m2 = if lightness <= 0.5 { lightness * (saturation + 1.) }
172168
else { lightness + saturation - lightness * saturation };
173169
let m1 = lightness * 2. - m2;
174-
red = hue_to_rgb(m1, m2, hue + 1. / 3.) as ColorFloat;
175-
green = hue_to_rgb(m1, m2, hue) as ColorFloat;
176-
blue = hue_to_rgb(m1, m2, hue - 1. / 3.) as ColorFloat;
170+
red = hue_to_rgb(m1, m2, hue + 1. / 3.) as f32;
171+
green = hue_to_rgb(m1, m2, hue) as f32;
172+
blue = hue_to_rgb(m1, m2, hue - 1. / 3.) as f32;
177173
}
178174

179175
let alpha = if has_alpha {
180176
expect_comma!();
181-
(expect_number!()).max(&0.).min(&1.) as ColorFloat
177+
(expect_number!()).max(&0.).min(&1.) as f32
182178
} else {
183179
1.
184180
};

lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
#[feature(globs, macro_rules, struct_variant)];
7+
#[feature(globs, macro_rules)];
88

99
extern mod extra;
1010

tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ impl ToJson for ComponentValue {
325325
Dimension(ref value, ref unit)
326326
=> JList(~[JString(~"dimension")] + numeric(value) + ~[unit.to_json()]),
327327
328-
UnicodeRange { start: s, end: e }
329-
=> JList(~[JString(~"unicode-range"), s.to_json(), e.to_json()]),
328+
UnicodeRange(start, end)
329+
=> JList(~[JString(~"unicode-range"), start.to_json(), end.to_json()]),
330330
331331
WhiteSpace => JString(~" "),
332332
Colon => JString(~":"),

tokenizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ fn consume_unicode_range(tokenizer: &mut Tokenizer) -> ComponentValue {
565565
}
566566
end = if hex.len() > 0 { num::from_str_radix(hex, 16).unwrap() } else { start }
567567
}
568-
UnicodeRange {start: start, end: end}
568+
UnicodeRange(start, end)
569569
}
570570

571571

0 commit comments

Comments
 (0)