Skip to content

Commit d73c9ed

Browse files
committed
Merge pull request servo#46 from SimonSapin/rustup_20140508
Upgrade to Rust aa67254 2014-05-08
2 parents 5448e90 + 8ff0c64 commit d73c9ed

File tree

9 files changed

+144
-137
lines changed

9 files changed

+144
-137
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.o
22
*.a
33
*.so
4+
*.rlib
45
*.dylib
56
*.dSYM
67
*.dll

ast.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
use std::fmt;
66
use std::slice;
7+
use std::vec;
78

89

910
#[deriving(Eq)]
1011
pub struct NumericValue {
11-
pub representation: ~str,
12+
pub representation: StrBuf,
1213
pub value: f64,
1314
pub int_value: Option<i64>,
1415
}
@@ -27,16 +28,16 @@ pub type Node = (ComponentValue, SourceLocation); // TODO this is not a good na
2728
#[deriving(Eq)]
2829
pub enum ComponentValue {
2930
// Preserved tokens.
30-
Ident(~str),
31-
AtKeyword(~str),
32-
Hash(~str),
33-
IDHash(~str), // Hash that is a valid ID selector.
34-
String(~str),
35-
URL(~str),
31+
Ident(StrBuf),
32+
AtKeyword(StrBuf),
33+
Hash(StrBuf),
34+
IDHash(StrBuf), // Hash that is a valid ID selector.
35+
String(StrBuf),
36+
URL(StrBuf),
3637
Delim(char),
3738
Number(NumericValue),
3839
Percentage(NumericValue),
39-
Dimension(NumericValue, ~str),
40+
Dimension(NumericValue, StrBuf),
4041
UnicodeRange(u32, u32), // (start, end) of range
4142
WhiteSpace,
4243
Colon, // :
@@ -52,12 +53,12 @@ pub enum ComponentValue {
5253
CDC, // -->
5354

5455
// Function
55-
Function(~str, ~[ComponentValue]), // name, arguments
56+
Function(StrBuf, Vec<ComponentValue>), // name, arguments
5657

5758
// Simple block
58-
ParenthesisBlock(~[ComponentValue]), // (…)
59-
SquareBracketBlock(~[ComponentValue]), // […]
60-
CurlyBracketBlock(~[Node]), // {…}
59+
ParenthesisBlock(Vec<ComponentValue>), // (…)
60+
SquareBracketBlock(Vec<ComponentValue>), // […]
61+
CurlyBracketBlock(Vec<Node>), // {…}
6162

6263
// These are always invalid
6364
BadURL,
@@ -71,24 +72,24 @@ pub enum ComponentValue {
7172
#[deriving(Eq)]
7273
pub struct Declaration {
7374
pub location: SourceLocation,
74-
pub name: ~str,
75-
pub value: ~[ComponentValue],
75+
pub name: StrBuf,
76+
pub value: Vec<ComponentValue>,
7677
pub important: bool,
7778
}
7879

7980
#[deriving(Eq)]
8081
pub struct QualifiedRule {
8182
pub location: SourceLocation,
82-
pub prelude: ~[ComponentValue],
83-
pub block: ~[Node],
83+
pub prelude: Vec<ComponentValue>,
84+
pub block: Vec<Node>,
8485
}
8586

8687
#[deriving(Eq)]
8788
pub struct AtRule {
8889
pub location: SourceLocation,
89-
pub name: ~str,
90-
pub prelude: ~[ComponentValue],
91-
pub block: Option<~[Node]>,
90+
pub name: StrBuf,
91+
pub prelude: Vec<ComponentValue>,
92+
pub block: Option<Vec<Node>>,
9293
}
9394

9495
#[deriving(Eq)]
@@ -156,14 +157,14 @@ pub trait MoveSkipWhitespaceIterable {
156157
fn move_skip_whitespace(self) -> MoveSkipWhitespaceIterator;
157158
}
158159

159-
impl MoveSkipWhitespaceIterable for ~[ComponentValue] {
160+
impl MoveSkipWhitespaceIterable for Vec<ComponentValue> {
160161
fn move_skip_whitespace(self) -> MoveSkipWhitespaceIterator {
161162
MoveSkipWhitespaceIterator{ iter_with_whitespace: self.move_iter() }
162163
}
163164
}
164165

165166
pub struct MoveSkipWhitespaceIterator {
166-
iter_with_whitespace: slice::MoveItems<ComponentValue>,
167+
iter_with_whitespace: vec::MoveItems<ComponentValue>,
167168
}
168169

169170
impl Iterator<ComponentValue> for MoveSkipWhitespaceIterator {

color.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ pub enum Color {
2828
impl Color {
2929
pub fn parse(component_value: &ComponentValue) -> Option<Color> {
3030
match *component_value {
31-
Hash(ref value) | IDHash(ref value) => parse_color_hash(*value),
32-
Ident(ref value) => parse_color_keyword(*value),
33-
Function(ref name, ref arguments) => parse_color_function(*name, *arguments),
31+
Hash(ref value) | IDHash(ref value) => parse_color_hash(value.as_slice()),
32+
Ident(ref value) => parse_color_keyword(value.as_slice()),
33+
Function(ref name, ref arguments)
34+
=> parse_color_function(name.as_slice(), arguments.as_slice()),
3435
_ => None
3536
}
3637
}

from_bytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use parser::{parse_stylesheet_rules, StylesheetParser};
3333
/// and the `Encoding` object that was used.
3434
pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>,
3535
environment_encoding: Option<EncodingRef>)
36-
-> (~str, EncodingRef) {
36+
-> (StrBuf, EncodingRef) {
3737
// http://dev.w3.org/csswg/css-syntax/#the-input-byte-stream
3838
match protocol_encoding_label {
3939
None => (),
@@ -71,7 +71,7 @@ pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>
7171

7272

7373
#[inline]
74-
fn decode_replace(input: &[u8], fallback_encoding: EncodingRef)-> (~str, EncodingRef) {
74+
fn decode_replace(input: &[u8], fallback_encoding: EncodingRef)-> (StrBuf, EncodingRef) {
7575
let (result, used_encoding) = decode(input, DecodeReplace, fallback_encoding);
7676
(result.unwrap(), used_encoding)
7777
}
@@ -97,5 +97,5 @@ pub fn parse_stylesheet_rules_from_bytes(
9797
-> (StylesheetParser<Tokenizer>, EncodingRef) {
9898
let (css_unicode, encoding) = decode_stylesheet_bytes(
9999
css_bytes, protocol_encoding_label, environment_encoding);
100-
(parse_stylesheet_rules(tokenize(css_unicode)), encoding)
100+
(parse_stylesheet_rules(tokenize(css_unicode.as_slice())), encoding)
101101
}

nth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn parse_n_dash_digits(string: &str) -> Option<i32> {
116116

117117
#[inline]
118118
fn has_sign(value: &NumericValue) -> bool {
119-
match value.representation[0] as char {
119+
match value.representation.as_bytes()[0] as char {
120120
'+' | '-' => true,
121121
_ => false
122122
}

parser.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use std::ascii::StrAsciiExt;
2020
use ast::*;
2121

2222

23-
pub struct StylesheetParser<T>{ priv iter: T }
24-
pub struct RuleListParser<T>{ priv iter: T }
25-
pub struct DeclarationListParser<T>{ priv iter: T }
23+
pub struct StylesheetParser<T>{ iter: T }
24+
pub struct RuleListParser<T>{ iter: T }
25+
pub struct DeclarationListParser<T>{ iter: T }
2626

2727
/// Parse top-level of a CSS stylesheet.
2828
/// Return a Iterator<Result<Rule, SyntaxError>>
@@ -173,9 +173,9 @@ for DeclarationListParser<T> {
173173
}
174174

175175

176-
fn parse_at_rule<T: Iterator<Node>>(iter: &mut T, name: ~str, location: SourceLocation)
176+
fn parse_at_rule<T: Iterator<Node>>(iter: &mut T, name: StrBuf, location: SourceLocation)
177177
-> AtRule {
178-
let mut prelude = ~[];
178+
let mut prelude = Vec::new();
179179
let mut block = None;
180180
for_iter!(iter, (component_value, _location), {
181181
match component_value {
@@ -193,10 +193,10 @@ fn parse_qualified_rule<T: Iterator<Node>>(iter: &mut T, first: ComponentValue,
193193
-> Result<QualifiedRule, SyntaxError> {
194194
match first {
195195
CurlyBracketBlock(content)
196-
=> return Ok(QualifiedRule { location: location, prelude: ~[], block: content }),
196+
=> return Ok(QualifiedRule { location: location, prelude: Vec::new(), block: content }),
197197
_ => (),
198198
}
199-
let mut prelude = ~[first];
199+
let mut prelude = vec!(first);
200200
for_iter!(iter, (component_value, _location), {
201201
match component_value {
202202
CurlyBracketBlock(content)
@@ -219,7 +219,7 @@ fn parse_declaration<T: Iterator<Node>>(iter: &mut T, first: ComponentValue,
219219
Some((Colon, _)) => (),
220220
_ => return error(location, ErrInvalidDeclarationSyntax),
221221
}
222-
let mut value = ~[];
222+
let mut value = Vec::new();
223223
let mut important = false;
224224
for_iter!(iter, (component_value, _location), {
225225
match component_value {
@@ -243,7 +243,7 @@ fn parse_declaration_important<T: Iterator<Node>>(iter: &mut T) -> bool {
243243
Some((Ident(value), _)) => value,
244244
_ => return false,
245245
};
246-
if !ident_value.eq_ignore_ascii_case("important") { return false }
246+
if !ident_value.as_slice().eq_ignore_ascii_case("important") { return false }
247247
match next_non_whitespace(iter) {
248248
Some((Semicolon, _)) => true,
249249
None => true,

serializer.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use ast::*;
77

88

99
impl ast::ComponentValue {
10-
pub fn to_css(&mut self) -> ~str {
11-
let mut css = ~"";
10+
pub fn to_css(&mut self) -> StrBuf {
11+
let mut css = StrBuf::new();
1212
self.to_css_push(&mut css);
1313
css
1414
}
1515

16-
pub fn to_css_push(&self, css: &mut ~str) {
16+
pub fn to_css_push(&self, css: &mut StrBuf) {
1717
match *self {
1818
Ident(ref value) => serialize_identifier(value.as_slice(), css),
1919
AtKeyword(ref value) => {
@@ -22,7 +22,7 @@ impl ast::ComponentValue {
2222
},
2323
Hash(ref value) => {
2424
css.push_char('#');
25-
for c in value.chars() {
25+
for c in value.as_slice().chars() {
2626
serialize_char(c, css, /* is_identifier_start = */ false);
2727
}
2828
},
@@ -38,13 +38,13 @@ impl ast::ComponentValue {
3838
},
3939
Delim(value) => css.push_char(value),
4040

41-
Number(ref value) => css.push_str(value.representation),
41+
Number(ref value) => css.push_str(value.representation.as_slice()),
4242
Percentage(ref value) => {
43-
css.push_str(value.representation);
43+
css.push_str(value.representation.as_slice());
4444
css.push_char('%');
4545
},
4646
Dimension(ref value, ref unit) => {
47-
css.push_str(value.representation);
47+
css.push_str(value.representation.as_slice());
4848
// Disambiguate with scientific notation.
4949
let unit = unit.as_slice();
5050
if unit == "e" || unit == "E" || unit.starts_with("e-") || unit.starts_with("E-") {
@@ -109,7 +109,7 @@ impl ast::ComponentValue {
109109
}
110110

111111

112-
pub fn serialize_identifier(value: &str, css: &mut ~str) {
112+
pub fn serialize_identifier(value: &str, css: &mut StrBuf) {
113113
// TODO: avoid decoding/re-encoding UTF-8?
114114
let mut iter = value.chars();
115115
let mut c = iter.next().unwrap();
@@ -127,7 +127,7 @@ pub fn serialize_identifier(value: &str, css: &mut ~str) {
127127

128128

129129
#[inline]
130-
fn serialize_char(c: char, css: &mut ~str, is_identifier_start: bool) {
130+
fn serialize_char(c: char, css: &mut StrBuf, is_identifier_start: bool) {
131131
match c {
132132
'0'..'9' if is_identifier_start => css.push_str(format!("\\\\3{} ", c)),
133133
'-' if is_identifier_start => css.push_str("\\-"),
@@ -141,7 +141,7 @@ fn serialize_char(c: char, css: &mut ~str, is_identifier_start: bool) {
141141
}
142142

143143

144-
pub fn serialize_string(value: &str, css: &mut ~str) {
144+
pub fn serialize_string(value: &str, css: &mut StrBuf) {
145145
css.push_char('"');
146146
// TODO: avoid decoding/re-encoding UTF-8?
147147
for c in value.chars() {
@@ -159,18 +159,18 @@ pub fn serialize_string(value: &str, css: &mut ~str) {
159159

160160

161161
pub trait ToCss {
162-
fn to_css(&mut self) -> ~str {
163-
let mut css = ~"";
162+
fn to_css(&mut self) -> StrBuf {
163+
let mut css = StrBuf::new();
164164
self.to_css_push(&mut css);
165165
css
166166
}
167167

168-
fn to_css_push(&mut self, css: &mut ~str);
168+
fn to_css_push(&mut self, css: &mut StrBuf);
169169
}
170170

171171

172172
impl<'a, I: Iterator<&'a ComponentValue>> ToCss for I {
173-
fn to_css_push(&mut self, css: &mut ~str) {
173+
fn to_css_push(&mut self, css: &mut StrBuf) {
174174
let mut previous = match self.next() {
175175
None => return,
176176
Some(first) => { first.to_css_push(css); first }

0 commit comments

Comments
 (0)