Skip to content

Commit e985dba

Browse files
author
Martijn Groeneveldt
committed
Merge remote-tracking branch 'source/master' into implement-std-error
2 parents 51312ea + 2c5c2ef commit e985dba

File tree

9 files changed

+241
-228
lines changed

9 files changed

+241
-228
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rust:
33
- nightly
44
- beta
55
- stable
6-
- 1.30.0
6+
- 1.36.0
77

88
script:
99
- cargo build --verbose

Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.25.8"
3+
version = "0.26.0"
44
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"
@@ -19,21 +19,19 @@ difference = "2.0"
1919
encoding_rs = "0.8"
2020

2121
[dependencies]
22-
cssparser-macros = {path = "./macros", version = "0.3.3"}
22+
cssparser-macros = {path = "./macros", version = "0.4"}
2323
dtoa-short = "0.3"
2424
heapsize = {version = ">= 0.3, < 0.5", optional = true}
2525
itoa = "0.4"
2626
matches = "0.1"
27-
phf = "0.7"
28-
procedural-masquerade = {path = "./procedural-masquerade", version = "0.1"}
27+
phf = {version = "0.8", features = ["macros"]}
2928
serde = {version = "1.0", optional = true}
3029
smallvec = "0.6"
3130

3231
[build-dependencies]
33-
autocfg = "0.1.4"
34-
syn = { version = "0.15.12", features = ["extra-traits", "fold", "full"] }
35-
quote = "0.6"
36-
proc-macro2 = "0.4"
32+
syn = { version = "1", features = ["extra-traits", "fold", "full"] }
33+
quote = "1"
34+
proc-macro2 = "1"
3735

3836
[features]
3937
bench = []

build.rs

Lines changed: 0 additions & 3 deletions
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-
extern crate autocfg;
65
#[macro_use]
76
extern crate quote;
87
#[macro_use]
@@ -50,7 +49,5 @@ fn main() {
5049
println!("cargo:rustc-cfg=rustc_has_pr45225")
5150
}
5251

53-
autocfg::new().emit_has_path("std::mem::MaybeUninit");
54-
5552
codegen::main();
5653
}

build/match_byte.rs

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,54 @@ fn get_byte_from_expr_lit(expr: &Box<syn::Expr>) -> u8 {
7272
}
7373
}
7474

75+
/// Parse a pattern and fill the table accordingly
76+
fn parse_pat_to_table<'a>(pat: &'a syn::Pat, case_id: u8, wildcard: &mut Option<&'a syn::Ident>, table: &mut [u8; 256]) {
77+
match pat {
78+
&syn::Pat::Lit(syn::PatLit { ref expr, .. }) => {
79+
let value = get_byte_from_expr_lit(expr);
80+
if table[value as usize] == 0 {
81+
table[value as usize] = case_id;
82+
}
83+
}
84+
&syn::Pat::Range(syn::PatRange { ref lo, ref hi, .. }) => {
85+
let lo = get_byte_from_expr_lit(lo);
86+
let hi = get_byte_from_expr_lit(hi);
87+
for value in lo..hi {
88+
if table[value as usize] == 0 {
89+
table[value as usize] = case_id;
90+
}
91+
}
92+
if table[hi as usize] == 0 {
93+
table[hi as usize] = case_id;
94+
}
95+
}
96+
&syn::Pat::Wild(_) => {
97+
for byte in table.iter_mut() {
98+
if *byte == 0 {
99+
*byte = case_id;
100+
}
101+
}
102+
}
103+
&syn::Pat::Ident(syn::PatIdent { ref ident, .. }) => {
104+
assert_eq!(*wildcard, None);
105+
*wildcard = Some(ident);
106+
for byte in table.iter_mut() {
107+
if *byte == 0 {
108+
*byte = case_id;
109+
}
110+
}
111+
},
112+
&syn::Pat::Or(syn::PatOr { ref cases, .. }) => {
113+
for case in cases {
114+
parse_pat_to_table(case, case_id, wildcard, table);
115+
}
116+
}
117+
_ => {
118+
panic!("Unexpected pattern: {:?}. Buggy code ?", pat);
119+
}
120+
}
121+
}
122+
75123
/// Expand a TokenStream corresponding to the `match_byte` macro.
76124
///
77125
/// ## Example
@@ -97,48 +145,8 @@ fn expand_match_byte(body: &TokenStream) -> syn::Expr {
97145
let case_id = i + 1;
98146
let index = case_id as isize;
99147
let name = syn::Ident::new(&format!("Case{}", case_id), Span::call_site());
148+
parse_pat_to_table(&arm.pat, case_id as u8, &mut wildcard, &mut table);
100149

101-
for pat in &arm.pats {
102-
match pat {
103-
&syn::Pat::Lit(syn::PatLit { ref expr }) => {
104-
let value = get_byte_from_expr_lit(expr);
105-
if table[value as usize] == 0 {
106-
table[value as usize] = case_id as u8;
107-
}
108-
}
109-
&syn::Pat::Range(syn::PatRange { ref lo, ref hi, .. }) => {
110-
let lo = get_byte_from_expr_lit(lo);
111-
let hi = get_byte_from_expr_lit(hi);
112-
for value in lo..hi {
113-
if table[value as usize] == 0 {
114-
table[value as usize] = case_id as u8;
115-
}
116-
}
117-
if table[hi as usize] == 0 {
118-
table[hi as usize] = case_id as u8;
119-
}
120-
}
121-
&syn::Pat::Wild(_) => {
122-
for byte in table.iter_mut() {
123-
if *byte == 0 {
124-
*byte = case_id as u8;
125-
}
126-
}
127-
}
128-
&syn::Pat::Ident(syn::PatIdent { ref ident, .. }) => {
129-
assert_eq!(wildcard, None);
130-
wildcard = Some(ident);
131-
for byte in table.iter_mut() {
132-
if *byte == 0 {
133-
*byte = case_id as u8;
134-
}
135-
}
136-
}
137-
_ => {
138-
panic!("Unexpected pattern: {:?}. Buggy code ?", pat);
139-
}
140-
}
141-
}
142150
cases.push(quote!(#name = #index));
143151
let body = &arm.body;
144152
match_body.push(quote!(Case::#name => { #body }))
@@ -170,7 +178,7 @@ impl Fold for MatchByteParser {
170178
if mac.path == parse_quote!(match_byte) {
171179
return syn::fold::fold_stmt(
172180
self,
173-
syn::Stmt::Expr(expand_match_byte(&mac.tts)),
181+
syn::Stmt::Expr(expand_match_byte(&mac.tokens)),
174182
);
175183
}
176184
}
@@ -184,7 +192,7 @@ impl Fold for MatchByteParser {
184192
match expr {
185193
syn::Expr::Macro(syn::ExprMacro { ref mac, .. }) => {
186194
if mac.path == parse_quote!(match_byte) {
187-
return syn::fold::fold_expr(self, expand_match_byte(&mac.tts));
195+
return syn::fold::fold_expr(self, expand_match_byte(&mac.tokens));
188196
}
189197
}
190198
_ => {}

macros/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
[package]
22
name = "cssparser-macros"
3-
version = "0.3.5"
3+
version = "0.4.0"
44
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
55
description = "Procedural macros for cssparser"
66
documentation = "https://docs.rs/cssparser-macros/"
77
repository = "https://github.com/servo/rust-cssparser"
88
license = "MPL-2.0"
9+
edition = "2018"
910

1011
[lib]
1112
path = "lib.rs"
1213
proc-macro = true
1314

1415
[dependencies]
15-
procedural-masquerade = {path = "../procedural-masquerade", version = "0.1"}
16-
phf_codegen = "0.7"
17-
quote = "0.6"
18-
syn = {version = "0.15.12", features = ["full", "extra-traits"]}
19-
proc-macro2 = "0.4"
16+
quote = "1"
17+
syn = {version = "1", features = ["full", "extra-traits"]}

0 commit comments

Comments
 (0)