Skip to content

Commit 99ae7d3

Browse files
author
bors-servo
authored
Auto merge of #353 - Eijebong:synup, r=dtolnay+SimonSapin
Update syn and bump version
2 parents e83f525 + a3eda83 commit 99ae7d3

File tree

2 files changed

+83
-98
lines changed

2 files changed

+83
-98
lines changed

html5ever/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "html5ever"
4-
version = "0.22.4"
4+
version = "0.22.5"
55
authors = [ "The html5ever Project Developers" ]
66
license = "MIT / Apache-2.0"
77
repository = "https://github.com/servo/html5ever"
@@ -42,5 +42,5 @@ typed-arena = "1.3.0"
4242

4343
[build-dependencies]
4444
quote = "0.6"
45-
syn = { version = "0.14", features = ["extra-traits", "full", "fold"] }
45+
syn = { version = "0.15", features = ["extra-traits", "full", "fold"] }
4646
proc-macro2 = "0.4"

html5ever/macros/match_token.rs

Lines changed: 81 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ use std::io::{Read, Write};
106106
use std::path::Path;
107107
use syn;
108108
use syn::fold::Fold;
109+
use syn::parse::{Parse, ParseStream, Result};
110+
use syn::ext::IdentExt;
109111
use proc_macro2::TokenStream;
110112

111113
pub fn expand(from: &Path, to: &Path) {
@@ -121,7 +123,7 @@ pub fn expand(from: &Path, to: &Path) {
121123
struct MatchTokenParser {}
122124

123125
struct MatchToken {
124-
expr: syn::Expr,
126+
ident: syn::Ident,
125127
arms: Vec<MatchTokenArm>,
126128
}
127129

@@ -154,82 +156,89 @@ pub struct Tag {
154156
name: Option<syn::Ident>,
155157
}
156158

157-
impl syn::synom::Synom for Tag {
158-
named!(parse -> Self, do_parse!(
159-
punct!(<) >>
160-
closing: option!(punct!(/)) >>
161-
name: alt!(
162-
syn!(syn::Ident) => { |i| Some(i) }
163-
|
164-
punct!(_) => { |_| None }
165-
) >>
166-
punct!(>) >>
167-
(
168-
Tag {
169-
kind: if closing.is_some() { TagKind::EndTag } else { TagKind::StartTag },
170-
name: name
171-
}
172-
)
173-
));
159+
impl Parse for Tag {
160+
fn parse(input: ParseStream) -> Result<Self> {
161+
input.parse::<Token![<]>()?;
162+
let closing: Option<Token![/]> = input.parse()?;
163+
let name = match input.call(syn::Ident::parse_any)? {
164+
ref wildcard if wildcard == "_" => None,
165+
other => Some(other),
166+
};
167+
input.parse::<Token![>]>()?;
168+
Ok(Tag {
169+
kind: if closing.is_some() { TagKind::EndTag } else { TagKind::StartTag },
170+
name: name
171+
})
172+
}
174173
}
175174

176-
impl syn::synom::Synom for LHS {
177-
named!(parse -> Self, do_parse!(
178-
pats: alt!(
179-
syn!(syn::Pat) => { |p| LHS::Pattern(p) }
180-
|
181-
many0!(syn!(Tag)) => { |t| LHS::Tags(t) }
182-
) >>
183-
(
184-
pats
185-
)
186-
));
175+
impl Parse for LHS {
176+
fn parse(input: ParseStream) -> Result<Self> {
177+
if input.peek(Token![<]) {
178+
let mut tags = Vec::new();
179+
while !input.peek(Token![=>]) {
180+
tags.push(input.parse()?);
181+
}
182+
Ok(LHS::Tags(tags))
183+
} else {
184+
let p: syn::Pat = input.parse()?;
185+
Ok(LHS::Pattern(p))
186+
}
187+
}
187188
}
188189

189-
impl syn::synom::Synom for MatchTokenArm {
190-
named!(parse -> Self, do_parse!(
191-
binding: option!(
192-
do_parse!(
193-
name: syn!(syn::Ident) >>
194-
punct!(@) >>
195-
(
196-
name
197-
)
198-
)
199-
) >>
200-
lhs: syn!(LHS) >>
201-
punct!(=>) >>
202-
rhs: do_parse!(
203-
expr: alt!(
204-
expr_nosemi => { |e| RHS::Expression(e) }
205-
|
206-
syn!(syn::Expr) => { |e| RHS::Expression(e) }
207-
|
208-
keyword!(else) => { |_| RHS::Else }
209-
) >>
210-
option!(punct!(,)) >>
211-
(expr)
212-
) >>
213-
(
214-
MatchTokenArm {
215-
binding,
216-
lhs,
217-
rhs,
218-
}
219-
)
220-
));
190+
impl Parse for MatchTokenArm {
191+
fn parse(input: ParseStream) -> Result<Self> {
192+
let binding = if input.peek2(Token![@]) {
193+
let binding = input.parse::<syn::Ident>()?;
194+
input.parse::<Token![@]>()?;
195+
Some(binding)
196+
} else {
197+
None
198+
};
199+
let lhs = input.parse::<LHS>()?;
200+
input.parse::<Token![=>]>()?;
201+
let rhs = if input.peek(syn::token::Brace) {
202+
let block = input.parse::<syn::Block>().unwrap();
203+
let block = syn::ExprBlock {
204+
attrs: vec![],
205+
label: None,
206+
block,
207+
};
208+
input.parse::<Option<Token![,]>>()?;
209+
RHS::Expression(syn::Expr::Block(block))
210+
} else if input.peek(Token![else]) {
211+
input.parse::<Token![else]>()?;
212+
input.parse::<Token![,]>()?;
213+
RHS::Else
214+
} else {
215+
let expr = input.parse::<syn::Expr>().unwrap();
216+
input.parse::<Option<Token![,]>>()?;
217+
RHS::Expression(expr)
218+
};
219+
220+
Ok(MatchTokenArm {
221+
binding,
222+
lhs,
223+
rhs,
224+
})
225+
}
221226
}
222227

223-
impl syn::synom::Synom for MatchToken {
224-
named!(parse -> Self, do_parse!(
225-
expr: syn!(syn::Expr) >>
226-
arms: braces!(many0!(MatchTokenArm::parse)) >> (
227-
MatchToken {
228-
expr,
229-
arms: arms.1
230-
}
231-
)
232-
));
228+
impl Parse for MatchToken {
229+
fn parse(input: ParseStream) -> Result<Self> {
230+
let ident = input.parse::<syn::Ident>()?;
231+
let content;
232+
braced!(content in input);
233+
let mut arms = vec![];
234+
while !content.is_empty() {
235+
arms.push(content.parse()?);
236+
}
237+
Ok(MatchToken {
238+
ident,
239+
arms,
240+
})
241+
}
233242
}
234243

235244
pub fn expand_match_token(body: &TokenStream) -> syn::Expr {
@@ -240,7 +249,7 @@ pub fn expand_match_token(body: &TokenStream) -> syn::Expr {
240249

241250
fn expand_match_token_macro(match_token: MatchToken) -> TokenStream {
242251
let mut arms = match_token.arms;
243-
let to_be_matched = match_token.expr;
252+
let to_be_matched = match_token.ident;
244253
// Handle the last arm specially at the end.
245254
let last_arm = arms.pop().unwrap();
246255

@@ -438,27 +447,3 @@ fn make_tag_pattern(binding: &TokenStream, tag: Tag) -> TokenStream {
438447
}
439448
}
440449

441-
named!(expr_nosemi -> syn::Expr, map!(alt!(
442-
syn!(syn::ExprIf) => { syn::Expr::If }
443-
|
444-
syn!(syn::ExprIfLet) => { syn::Expr::IfLet }
445-
|
446-
syn!(syn::ExprWhile) => { syn::Expr::While }
447-
|
448-
syn!(syn::ExprWhileLet) => { syn::Expr::WhileLet }
449-
|
450-
syn!(syn::ExprForLoop) => { syn::Expr::ForLoop }
451-
|
452-
syn!(syn::ExprLoop) => { syn::Expr::Loop }
453-
|
454-
syn!(syn::ExprMatch) => { syn::Expr::Match }
455-
|
456-
syn!(syn::ExprCatch) => { syn::Expr::Catch }
457-
|
458-
syn!(syn::ExprYield) => { syn::Expr::Yield }
459-
|
460-
syn!(syn::ExprUnsafe) => { syn::Expr::Unsafe }
461-
|
462-
syn!(syn::ExprBlock) => { syn::Expr::Block }
463-
), syn::Expr::from));
464-

0 commit comments

Comments
 (0)