Skip to content

Commit a2e99f6

Browse files
committed
Upgrade to rustc 21d1f4d7c 2014-09-14
1 parent 9f9df95 commit a2e99f6

File tree

2 files changed

+98
-94
lines changed

2 files changed

+98
-94
lines changed

src/ast.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ pub enum ComponentValue {
6969
}
7070

7171

72+
impl ComponentValue {
73+
pub fn to_css(&mut self) -> String {
74+
let mut css = String::new();
75+
self.to_css_push(&mut css);
76+
css
77+
}
78+
79+
pub fn to_css_push(&self, css: &mut String) {
80+
::serializer::to_css_push(self, css)
81+
}
82+
}
83+
84+
7285
#[deriving(PartialEq)]
7386
pub struct Declaration {
7487
pub location: SourceLocation,

src/serializer.rs

Lines changed: 85 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,100 @@
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 ast;
65
use ast::*;
76

87

9-
impl ast::ComponentValue {
10-
pub fn to_css(&mut self) -> String {
11-
let mut css = String::new();
12-
self.to_css_push(&mut css);
13-
css
14-
}
15-
16-
pub fn to_css_push(&self, css: &mut String) {
17-
match *self {
18-
Ident(ref value) => serialize_identifier(value.as_slice(), css),
19-
AtKeyword(ref value) => {
20-
css.push_char('@');
21-
serialize_identifier(value.as_slice(), css);
22-
},
23-
Hash(ref value) => {
24-
css.push_char('#');
25-
for c in value.as_slice().chars() {
8+
pub fn to_css_push(component_value: &ComponentValue, css: &mut String) {
9+
match *component_value {
10+
Ident(ref value) => serialize_identifier(value.as_slice(), css),
11+
AtKeyword(ref value) => {
12+
css.push_char('@');
13+
serialize_identifier(value.as_slice(), css);
14+
},
15+
Hash(ref value) => {
16+
css.push_char('#');
17+
for c in value.as_slice().chars() {
18+
serialize_char(c, css, /* is_identifier_start = */ false);
19+
}
20+
},
21+
IDHash(ref value) => {
22+
css.push_char('#');
23+
serialize_identifier(value.as_slice(), css);
24+
}
25+
String(ref value) => serialize_string(value.as_slice(), css),
26+
URL(ref value) => {
27+
css.push_str("url(");
28+
serialize_string(value.as_slice(), css);
29+
css.push_char(')');
30+
},
31+
Delim(value) => css.push_char(value),
32+
33+
Number(ref value) => css.push_str(value.representation.as_slice()),
34+
Percentage(ref value) => {
35+
css.push_str(value.representation.as_slice());
36+
css.push_char('%');
37+
},
38+
Dimension(ref value, ref unit) => {
39+
css.push_str(value.representation.as_slice());
40+
// Disambiguate with scientific notation.
41+
let unit = unit.as_slice();
42+
if unit == "e" || unit == "E" || unit.starts_with("e-") || unit.starts_with("E-") {
43+
css.push_str("\\65 ");
44+
for c in unit.slice_from(1).chars() {
2645
serialize_char(c, css, /* is_identifier_start = */ false);
2746
}
28-
},
29-
IDHash(ref value) => {
30-
css.push_char('#');
31-
serialize_identifier(value.as_slice(), css);
47+
} else {
48+
serialize_identifier(unit, css)
3249
}
33-
String(ref value) => serialize_string(value.as_slice(), css),
34-
URL(ref value) => {
35-
css.push_str("url(");
36-
serialize_string(value.as_slice(), css);
37-
css.push_char(')');
38-
},
39-
Delim(value) => css.push_char(value),
40-
41-
Number(ref value) => css.push_str(value.representation.as_slice()),
42-
Percentage(ref value) => {
43-
css.push_str(value.representation.as_slice());
44-
css.push_char('%');
45-
},
46-
Dimension(ref value, ref unit) => {
47-
css.push_str(value.representation.as_slice());
48-
// Disambiguate with scientific notation.
49-
let unit = unit.as_slice();
50-
if unit == "e" || unit == "E" || unit.starts_with("e-") || unit.starts_with("E-") {
51-
css.push_str("\\65 ");
52-
for c in unit.slice_from(1).chars() {
53-
serialize_char(c, css, /* is_identifier_start = */ false);
54-
}
55-
} else {
56-
serialize_identifier(unit, css)
57-
}
58-
},
50+
},
5951

60-
UnicodeRange(start, end) => {
61-
css.push_str(format!("U+{:X}", start).as_slice());
62-
if end != start {
63-
css.push_str(format!("-{:X}", end).as_slice());
64-
}
52+
UnicodeRange(start, end) => {
53+
css.push_str(format!("U+{:X}", start).as_slice());
54+
if end != start {
55+
css.push_str(format!("-{:X}", end).as_slice());
6556
}
66-
67-
WhiteSpace => css.push_char(' '),
68-
Colon => css.push_char(':'),
69-
Semicolon => css.push_char(';'),
70-
Comma => css.push_char(','),
71-
IncludeMatch => css.push_str("~="),
72-
DashMatch => css.push_str("|="),
73-
PrefixMatch => css.push_str("^="),
74-
SuffixMatch => css.push_str("$="),
75-
SubstringMatch => css.push_str("*="),
76-
Column => css.push_str("||"),
77-
CDO => css.push_str("<!--"),
78-
CDC => css.push_str("-->"),
79-
80-
Function(ref name, ref arguments) => {
81-
serialize_identifier(name.as_slice(), css);
82-
css.push_char('(');
83-
arguments.iter().to_css_push(css);
84-
css.push_char(')');
85-
},
86-
ParenthesisBlock(ref content) => {
87-
css.push_char('(');
88-
content.iter().to_css_push(css);
89-
css.push_char(')');
90-
},
91-
SquareBracketBlock(ref content) => {
92-
css.push_char('[');
93-
content.iter().to_css_push(css);
94-
css.push_char(']');
95-
},
96-
CurlyBracketBlock(ref content) => {
97-
css.push_char('{');
98-
content.iter().map(|t| match *t { (ref c, _) => c }).to_css_push(css);
99-
css.push_char('}');
100-
},
101-
102-
BadURL => css.push_str("url(<bad url>)"),
103-
BadString => css.push_str("\"<bad string>\n"),
104-
CloseParenthesis => css.push_char(')'),
105-
CloseSquareBracket => css.push_char(']'),
106-
CloseCurlyBracket => css.push_char('}'),
10757
}
58+
59+
WhiteSpace => css.push_char(' '),
60+
Colon => css.push_char(':'),
61+
Semicolon => css.push_char(';'),
62+
Comma => css.push_char(','),
63+
IncludeMatch => css.push_str("~="),
64+
DashMatch => css.push_str("|="),
65+
PrefixMatch => css.push_str("^="),
66+
SuffixMatch => css.push_str("$="),
67+
SubstringMatch => css.push_str("*="),
68+
Column => css.push_str("||"),
69+
CDO => css.push_str("<!--"),
70+
CDC => css.push_str("-->"),
71+
72+
Function(ref name, ref arguments) => {
73+
serialize_identifier(name.as_slice(), css);
74+
css.push_char('(');
75+
arguments.iter().to_css_push(css);
76+
css.push_char(')');
77+
},
78+
ParenthesisBlock(ref content) => {
79+
css.push_char('(');
80+
content.iter().to_css_push(css);
81+
css.push_char(')');
82+
},
83+
SquareBracketBlock(ref content) => {
84+
css.push_char('[');
85+
content.iter().to_css_push(css);
86+
css.push_char(']');
87+
},
88+
CurlyBracketBlock(ref content) => {
89+
css.push_char('{');
90+
content.iter().map(|t| match *t { (ref c, _) => c }).to_css_push(css);
91+
css.push_char('}');
92+
},
93+
94+
BadURL => css.push_str("url(<bad url>)"),
95+
BadString => css.push_str("\"<bad string>\n"),
96+
CloseParenthesis => css.push_char(')'),
97+
CloseSquareBracket => css.push_char(']'),
98+
CloseCurlyBracket => css.push_char('}'),
10899
}
109100
}
110101

0 commit comments

Comments
 (0)