Skip to content

Commit

Permalink
Bump syn build dependency to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanahsmith committed Mar 22, 2023
1 parent 304e89a commit eb820a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rb-sys-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ regex = "1"
shell-words = "1.1"
bindgen = { version = "0.60", default-features = false, features = ["runtime"] }
cc-impl = { version = "1.0", optional = true, package = "cc" }
syn = { version = "1.0", features = ["parsing", "full", "extra-traits"] }
syn = { version = "2.0", features = ["parsing", "full", "extra-traits"] }
quote = "1.0.23"
lazy_static = "1.4.0"
proc-macro2 = "1.0.52"
Expand Down
35 changes: 15 additions & 20 deletions crates/rb-sys-build/src/bindings/sanitizer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use proc_macro2::{Literal, TokenTree};
use quote::ToTokens;
use regex::Regex;
use std::{borrow::Cow, error::Error};
use syn::{Attribute, Item};
use std::{
borrow::{Borrow, Cow},
error::Error,
};
use syn::{Attribute, Expr, Item, Lit, LitStr, Meta};

lazy_static::lazy_static! {
static ref URL_REGEX: Regex = Regex::new(r#"https?://[^\s'"]+"#).unwrap();
Expand Down Expand Up @@ -75,19 +76,16 @@ pub fn cleanup_docs(syntax: &mut syn::File, ruby_version: &str) -> Result<(), Bo
}

fn clean_doc_line(attr: &mut Attribute) -> bool {
if !attr.path.is_ident("doc") {
if !attr.path().is_ident("doc") {
return false;
}

let mut deprecated: bool = false;

let new_tokens = attr
.tokens
.to_token_stream()
.into_iter()
.map(|token| {
if let TokenTree::Literal(l) = token {
let cleaned = l.to_string();
if let Meta::NameValue(name_value) = &mut attr.meta {
if let Expr::Lit(expr_lit) = &mut name_value.value {
if let Lit::Str(lit_str) = &mut expr_lit.lit {
let cleaned = lit_str.value();
let cleaned = cleaned.trim_matches('"').trim();
let cleaned = URL_REGEX.replace_all(cleaned, "<${0}>");
let cleaned =
Expand All @@ -100,24 +98,21 @@ fn clean_doc_line(attr: &mut Attribute) -> bool {
});
let cleaned = PARAM_DIRECTIVE_REGEX.replace(&cleaned, "- **$1** `$2` $3");
let cleaned = OTHER_DIRECTIVE_REGEX.replace(&cleaned, "- **$1** $2");
let cleaned = BARE_CODE_REF_REGEX.replace_all(&cleaned, "${1}[`${2}`]");
let mut cleaned = BARE_CODE_REF_REGEX.replace_all(&cleaned, "${1}[`${2}`]");

if cleaned.is_empty() {
return TokenTree::Literal(Literal::string("\n"));
cleaned = "\n".into();
}

if cleaned.contains("@deprecated") {
deprecated = true;
}

Literal::string(&cleaned).into()
} else {
token
*lit_str = LitStr::new(cleaned.borrow(), lit_str.span());
}
})
.collect();
}
}

attr.tokens = new_tokens;
deprecated
}

Expand Down
8 changes: 4 additions & 4 deletions examples/rust_reverse/ext/rust_reverse/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb820a6

Please sign in to comment.