From a22bd9a13ba475c6bac8305c636f9dd3f5bd9d30 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Apr 04 2018 09:09:15 +0000 Subject: Update to 0.23.4 Signed-off-by: Igor Gnatenko --- diff --git a/.gitignore b/.gitignore index 87aec8b..9076075 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /cssparser-0.23.2.crate +/cssparser-0.23.4.crate diff --git a/0001-Update-syn-to-0.12-and-quote-to-0.4.patch b/0001-Update-syn-to-0.12-and-quote-to-0.4.patch deleted file mode 100644 index ba143c0..0000000 --- a/0001-Update-syn-to-0.12-and-quote-to-0.4.patch +++ /dev/null @@ -1,428 +0,0 @@ -From a244c3c36194a90e8081a1a89bf424a3cc70294d Mon Sep 17 00:00:00 2001 -From: Bastien Orivel -Date: Thu, 11 Jan 2018 13:38:20 +0100 -Subject: [PATCH] Update syn to 0.12 and quote to 0.4 - ---- - build.rs | 3 + - build/match_byte.rs | 345 +++++++++++++++++++--------------------------------- - 2 files changed, 129 insertions(+), 219 deletions(-) - -diff --git a/build.rs b/build.rs -index 5c06d29..70339f4 100644 ---- a/build.rs -+++ b/build.rs -@@ -2,8 +2,11 @@ - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -+#[macro_use] - extern crate quote; -+#[macro_use] - extern crate syn; -+extern crate proc_macro2; - - use std::env; - use std::path::Path; -diff --git a/build/match_byte.rs b/build/match_byte.rs -index 6680c67..cbf62a5 100644 ---- a/build/match_byte.rs -+++ b/build/match_byte.rs -@@ -2,83 +2,63 @@ - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - --use quote::{ToTokens, Tokens}; -+use quote::ToTokens; - use std::fs::File; - use std::io::{Read, Write}; - use std::path::Path; --use std::vec; --use std::iter; - use syn; -+use syn::fold::Fold; -+ -+use proc_macro2::TokenStream; -+ -+struct MatchByteParser { -+} - - pub fn expand(from: &Path, to: &Path) { - let mut source = String::new(); - File::open(from).unwrap().read_to_string(&mut source).unwrap(); -- let tts = syn::parse_token_trees(&source).expect("Parsing rules.rs module"); -- let mut tokens = Tokens::new(); -- tokens.append_all(expand_tts(tts)); -+ let ast = syn::parse_file(&source).expect("Parsing rules.rs module"); -+ let mut m = MatchByteParser {}; -+ let ast = m.fold_file(ast); - -- let code = tokens.to_string().replace("{ ", "{\n").replace(" }", "\n}"); -+ let code = ast.into_tokens().to_string().replace("{ ", "{\n").replace(" }", "\n}"); - File::create(to).unwrap().write_all(code.as_bytes()).unwrap(); - } - --fn expand_tts(tts: Vec) -> Vec { -- use syn::*; -- let mut expanded = Vec::new(); -- let mut tts = tts.into_iter(); -- while let Some(tt) = tts.next() { -- match tt { -- TokenTree::Token(Token::Ident(ident)) => { -- if ident != "match_byte" { -- expanded.push(TokenTree::Token(Token::Ident(ident))); -- continue; -- } -- -- match tts.next() { -- Some(TokenTree::Token(Token::Not)) => {}, -- other => { -- expanded.push(TokenTree::Token(Token::Ident(ident))); -- if let Some(other) = other { -- expanded.push(other); -- } -- continue; -- } -- } -- -- let tts = match tts.next() { -- Some(TokenTree::Delimited(Delimited { tts, .. })) => tts, -- other => { -- expanded.push(TokenTree::Token(Token::Ident(ident))); -- expanded.push(TokenTree::Token(Token::Not)); -- if let Some(other) = other { -- expanded.push(other); -- } -- continue; -- } -- }; -+struct MatchByte { -+ expr: syn::Expr, -+ arms: Vec, -+} - -- let (to_be_matched, table, cases, wildcard_binding) = parse_match_bytes_macro(tts); -- let expr = expand_match_bytes_macro(to_be_matched, -- &table, -- cases, -- wildcard_binding); -+impl syn::synom::Synom for MatchByte { -+ named!(parse -> Self, do_parse!( -+ expr: syn!(syn::Expr) >> -+ punct!(,) >> -+ arms: many0!(syn!(syn::Arm)) >> ( -+ MatchByte { -+ expr, -+ arms -+ } -+ ) -+ )); -+} - -- let tts = syn::parse_token_trees(&expr) -- .expect("parsing macro expansion as token trees"); -- expanded.extend(expand_tts(tts)); -+fn get_byte_from_expr_lit(expr: &Box) -> u8 { -+ match **expr { -+ syn::Expr::Lit(syn::ExprLit { ref lit, .. }) => { -+ if let syn::Lit::Byte(ref byte) = *lit { -+ byte.value() - } -- TokenTree::Delimited(Delimited { delim, tts }) => { -- expanded.push(TokenTree::Delimited(Delimited { -- delim: delim, -- tts: expand_tts(tts), -- })) -+ else { -+ panic!("Found a pattern that wasn't a byte") - } -- other => expanded.push(other), -- } -+ }, -+ _ => unreachable!(), - } -- expanded - } - --/// Parses a token tree corresponding to the `match_byte` macro. -+ -+/// Expand a TokenStream corresponding to the `match_byte` macro. - /// - /// ## Example - /// -@@ -88,184 +68,111 @@ fn expand_tts(tts: Vec) -> Vec { - /// b'0'..b'9' => { ... } - /// b'\n' | b'\\' => { ... } - /// foo => { ... } --/// } --/// --/// Returns: --/// * The token tree that contains the expression to be matched (in this case --/// `tokenizer.next_byte_unchecked()`. -+/// } -+/// ``` - /// --/// * The table with the different cases per byte, each entry in the table --/// contains a non-zero integer representing a different arm of the --/// match expression. --/// --/// * The list of cases containing the expansion of the arms of the match --/// expression. --/// --/// * An optional identifier to which the wildcard pattern is matched (`foo` in --/// this case). --/// --fn parse_match_bytes_macro(tts: Vec) -> (Vec, [u8; 256], Vec, Option) { -- let mut tts = tts.into_iter(); -- -- // Grab the thing we're matching, until we find a comma. -- let mut left_hand_side = vec![]; -- loop { -- match tts.next() { -- Some(syn::TokenTree::Token(syn::Token::Comma)) => break, -- Some(other) => left_hand_side.push(other), -- None => panic!("Expected not to run out of tokens looking for a comma"), -- } -- } -- -- let mut cases = vec![]; -+fn expand_match_byte(body: &TokenStream) -> syn::Expr { -+ let match_byte: MatchByte = syn::parse2(body.clone()).unwrap(); -+ let expr = match_byte.expr; -+ let mut cases = Vec::new(); - let mut table = [0u8; 256]; -- -- let mut tts = tts.peekable(); -- let mut case_id: u8 = 1; -- let mut binding = None; -- while tts.len() > 0 { -- cases.push(parse_case(&mut tts, &mut table, &mut binding, case_id)); -- -- // Allow an optional comma between cases. -- match tts.peek() { -- Some(&syn::TokenTree::Token(syn::Token::Comma)) => { -- tts.next(); -- }, -- _ => {}, -- } -- -- case_id += 1; -- } -- -- (left_hand_side, table, cases, binding) --} -- --#[derive(Debug)] --struct Case(Vec); -- --/// Parses a single pattern => expression, and returns the case, filling in the --/// table with the case id for every byte that matched. --/// --/// The `binding` parameter is the identifier that is used by the wildcard --/// pattern. --fn parse_case(tts: &mut iter::Peekable>, -- table: &mut [u8; 256], -- binding: &mut Option, -- case_id: u8) -- -> Case { -- // The last byte checked, as part of this pattern, to properly detect -- // ranges. -- let mut last_byte: Option = None; -- -- // Loop through the pattern filling with bytes the table. -- loop { -- match tts.next() { -- Some(syn::TokenTree::Token(syn::Token::Literal(syn::Lit::Byte(byte)))) => { -- table[byte as usize] = case_id; -- last_byte = Some(byte); -- } -- Some(syn::TokenTree::Token(syn::Token::BinOp(syn::BinOpToken::Or))) => { -- last_byte = None; // This pattern is over. -- }, -- Some(syn::TokenTree::Token(syn::Token::DotDotDot)) => { -- assert!(last_byte.is_some(), "Expected closed range!"); -- match tts.next() { -- Some(syn::TokenTree::Token(syn::Token::Literal(syn::Lit::Byte(byte)))) => { -- for b in last_byte.take().unwrap()..byte { -- if table[b as usize] == 0 { -- table[b as usize] = case_id; -- } -+ let mut match_body = Vec::new(); -+ let mut wildcard = None; -+ -+ for (i, ref arm) in match_byte.arms.iter().enumerate() { -+ let case_id = i + 1; -+ let index = case_id as isize; -+ let name = syn::Ident::from(format!("Case{}", case_id)); -+ -+ for pat in &arm.pats { -+ match pat { -+ &syn::Pat::Lit(syn::PatLit{ref expr}) => { -+ let value = get_byte_from_expr_lit(expr); -+ if table[value as usize] == 0 { -+ table[value as usize] = case_id as u8; -+ } -+ }, -+ &syn::Pat::Range(syn::PatRange { ref lo, ref hi, .. }) => { -+ let lo = get_byte_from_expr_lit(lo); -+ let hi = get_byte_from_expr_lit(hi); -+ for value in lo..hi { -+ if table[value as usize] == 0 { -+ table[value as usize] = case_id as u8; - } -- if table[byte as usize] == 0 { -- table[byte as usize] = case_id; -+ } -+ if table[hi as usize] == 0 { -+ table[hi as usize] = case_id as u8; -+ } -+ }, -+ &syn::Pat::Wild(_) => { -+ for byte in table.iter_mut() { -+ if *byte == 0 { -+ *byte = case_id as u8; - } - } -- other => panic!("Expected closed range, got: {:?}", other), -- } -- }, -- Some(syn::TokenTree::Token(syn::Token::FatArrow)) => break, -- Some(syn::TokenTree::Token(syn::Token::Ident(ident))) => { -- assert_eq!(last_byte, None, "I don't support ranges with identifiers!"); -- assert_eq!(*binding, None); -- for byte in table.iter_mut() { -- if *byte == 0 { -- *byte = case_id; -+ }, -+ &syn::Pat::Ident(syn::PatIdent { ident, .. }) => { -+ assert_eq!(wildcard, None); -+ wildcard = Some(ident); -+ for byte in table.iter_mut() { -+ if *byte == 0 { -+ *byte = case_id as u8; -+ } - } -+ }, -+ _ => { -+ panic!("Unexpected pattern: {:?}. Buggy code ?", pat); - } -- *binding = Some(ident) - } -- Some(syn::TokenTree::Token(syn::Token::Underscore)) => { -- assert_eq!(last_byte, None); -- for byte in table.iter_mut() { -- if *byte == 0 { -- *byte = case_id; -- } -- } -- }, -- other => panic!("Expected literal byte, got: {:?}", other), -- } -- } -- -- match tts.next() { -- Some(syn::TokenTree::Delimited(syn::Delimited { delim: syn::DelimToken::Brace, tts })) => { -- Case(tts) - } -- other => panic!("Expected case with braces after fat arrow, got: {:?}", other), -- } --} -- --fn expand_match_bytes_macro(to_be_matched: Vec, -- table: &[u8; 256], -- cases: Vec, -- binding: Option) -- -> String { -- use std::fmt::Write; -- -- assert!(!to_be_matched.is_empty()); -- assert!(table.iter().all(|b| *b != 0), "Incomplete pattern? Bogus code!"); -- -- // We build the expression with text since it's easier. -- let mut expr = "{\n".to_owned(); -- expr.push_str("enum Case {\n"); -- for (i, _) in cases.iter().enumerate() { -- write!(&mut expr, "Case{} = {},", i + 1, i + 1).unwrap(); -+ cases.push(quote!(#name = #index)); -+ let body = &arm.body; -+ match_body.push(quote!(Case::#name => { #body })) - } -- expr.push_str("}\n"); // enum Case -- -- expr.push_str("static __CASES: [Case; 256] = ["); -- for byte in table.iter() { -- write!(&mut expr, "Case::Case{}, ", *byte).unwrap(); -+ let en = quote!(enum Case { -+ #(#cases),* -+ }); -+ -+ let mut table_content = Vec::new(); -+ for entry in table.iter() { -+ let name: syn::Path = syn::parse_str(&format!("Case::Case{}", entry)).unwrap(); -+ table_content.push(name); - } -- expr.push_str("];\n"); -+ let table = quote!(static __CASES: [Case; 256] = [#(#table_content),*];); - -- let mut tokens = Tokens::new(); -- let to_be_matched = syn::Delimited { -- delim: if binding.is_some() { syn::DelimToken::Brace } else { syn::DelimToken::Paren }, -- tts: to_be_matched -+ let expr = if let Some(binding) = wildcard { -+ quote!({ #en #table let #binding = #expr; match __CASES[#binding as usize] { #(#match_body),* }}) -+ } else { -+ quote!({ #en #table match __CASES[#expr as usize] { #(#match_body),* }}) - }; -- to_be_matched.to_tokens(&mut tokens); - -- if let Some(ref binding) = binding { -- write!(&mut expr, "let {} = {};\n", binding.to_string(), tokens.as_str()).unwrap(); -- } -+ syn::parse2(expr.into()).unwrap() -+} - -- write!(&mut expr, "match __CASES[{} as usize] {{", match binding { -- Some(binding) => binding.to_string(), -- None => tokens.to_string(), -- }).unwrap(); -+impl Fold for MatchByteParser { -+ fn fold_stmt(&mut self, stmt: syn::Stmt) -> syn::Stmt { -+ match stmt { -+ syn::Stmt::Item(syn::Item::Macro(syn::ItemMacro{ ref mac, .. })) => { -+ if mac.path == parse_quote!(match_byte) { -+ return syn::fold::fold_stmt(self, syn::Stmt::Expr(expand_match_byte(&mac.tts))) -+ } -+ }, -+ _ => {} -+ } - -- for (i, case) in cases.into_iter().enumerate() { -- let mut case_tokens = Tokens::new(); -- let case = syn::Delimited { -- delim: syn::DelimToken::Brace, -- tts: case.0 -- }; -- case.to_tokens(&mut case_tokens); -- write!(&mut expr, "Case::Case{} => {},\n", i + 1, case_tokens.as_str()).unwrap(); -+ syn::fold::fold_stmt(self, stmt) - } -- expr.push_str("}\n"); // match - -- expr.push_str("}\n"); // top -+ fn fold_expr(&mut self, expr: syn::Expr) -> syn::Expr { -+ match expr { -+ syn::Expr::Macro(syn::ExprMacro{ ref mac, .. }) => { -+ if mac.path == parse_quote!(match_byte) { -+ return syn::fold::fold_expr(self, expand_match_byte(&mac.tts)) -+ } -+ }, -+ _ => {} -+ } - -- expr -+ syn::fold::fold_expr(self, expr) -+ } - } --- -2.16.2 - diff --git a/cssparser-0.23.2-fix-metadata.diff b/cssparser-0.23.2-fix-metadata.diff deleted file mode 100644 index 433bd76..0000000 --- a/cssparser-0.23.2-fix-metadata.diff +++ /dev/null @@ -1,37 +0,0 @@ ---- cssparser-0.23.2/Cargo.toml 1969-12-31T16:00:00-08:00 -+++ cssparser-0.23.2/Cargo.toml 2018-03-26T16:53:08.967126-07:00 -@@ -33,7 +33,7 @@ - optional = true - - [dependencies.itoa] --version = "0.3" -+version = "0.4" - - [dependencies.matches] - version = "0.1" -@@ -51,7 +51,7 @@ - [dependencies.smallvec] - version = "0.6" - [dev-dependencies.difference] --version = "1.0" -+version = "2.0" - - [dev-dependencies.encoding_rs] - version = "0.7" -@@ -59,10 +59,14 @@ - [dev-dependencies.rustc-serialize] - version = "0.3" - [build-dependencies.quote] --version = "0.3" -+version = "0.4.1" -+ -+[build-dependencies.proc-macro2] -+version = "0.2" - - [build-dependencies.syn] --version = "0.11" -+version = "0.12" -+features = ["extra-traits", "fold"] - - [features] - bench = [] diff --git a/rust-cssparser.spec b/rust-cssparser.spec index 5bbe38e..57f541d 100644 --- a/rust-cssparser.spec +++ b/rust-cssparser.spec @@ -5,19 +5,13 @@ %global crate cssparser Name: rust-%{crate} -Version: 0.23.2 -Release: 4%{?dist} +Version: 0.23.4 +Release: 1%{?dist} Summary: Rust implementation of CSS Syntax Level 3 License: MPLv2.0 URL: https://crates.io/crates/cssparser Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate -# Initial patched metadata -# * Bump difference to 2.0, https://github.com/servo/rust-cssparser/pull/212 -# * Bump syn to 0.12, quote to 0.4, https://github.com/servo/rust-cssparser/commit/a244c3c36194a90e8081a1a89bf424a3cc70294d -# * Bump itoa to 0.4, https://github.com/servo/rust-cssparser/pull/216 -Patch0: cssparser-0.23.2-fix-metadata.diff -Patch1: 0001-Update-syn-to-0.12-and-quote-to-0.4.patch ExclusiveArch: %{rust_arches} @@ -76,6 +70,9 @@ which use %{crate} from crates.io. %{cargo_registry}/%{crate}-%{version}/ %changelog +* Wed Apr 04 2018 Igor Gnatenko - 0.23.4-1 +- Update to 0.23.4 + * Mon Mar 26 2018 Josh Stone - 0.23.2-4 - Bump itoa to 0.4.0 diff --git a/sources b/sources index 639990d..3bca073 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (cssparser-0.23.2.crate) = 53d03959883a27143cf1447880ea2f3ed10580091b831e1e3d1c0726a7e4b82494849022dcc25e4c0aa60286dc573daf7c43986e7e0de651e9b98596db5c33c3 +SHA512 (cssparser-0.23.4.crate) = 3cce283fe47a9a38f4f49903cb709249a71fb1d1130b03e1826cd11f9c02bfa78e54b72fbbf35293849c89c8414b37ce520c8fd375e525a5db498a1f4ab37c07