Skip to content

Commit b43b481

Browse files
author
Martin Larralde
committed
Merge #154 and #155 changed with syn13
1 parent 103bde7 commit b43b481

File tree

12 files changed

+516
-524
lines changed

12 files changed

+516
-524
lines changed

pyo3-derive-backend/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ categories = ["api-bindings", "development-tools::ffi"]
1010
license = "Apache-2.0"
1111

1212
[dependencies]
13-
quote="0.3"
1413
log="0.4"
14+
quote="0.5"
1515

1616
[dependencies.syn]
17-
version="0.11"
18-
features=["full"]
17+
version="0.13"
18+
features=["full", "parsing", "printing", "extra-traits"]

pyo3-derive-backend/src/args.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub enum Argument {
1010
Kwarg(String, String),
1111
}
1212

13-
pub fn parse_arguments(items: &[syn::NestedMetaItem]) -> Vec<Argument> {
13+
pub fn parse_arguments(items: &[syn::NestedMeta]) -> Vec<Argument> {
1414
let mut arguments = Vec::new();
1515
let mut has_kw = false;
1616
let mut has_varargs = false;
@@ -22,7 +22,7 @@ pub fn parse_arguments(items: &[syn::NestedMetaItem]) -> Vec<Argument> {
2222

2323
for item in items.iter() {
2424
match item {
25-
&syn::NestedMetaItem::MetaItem(syn::MetaItem::Word(ref ident)) => {
25+
&syn::NestedMeta::Meta(syn::Meta::Word(ref ident)) => {
2626
// arguments in form #[args(somename)]
2727
if has_kwargs {
2828
println!("syntax error, keyword arguments is defined: {:?}", args_str);
@@ -35,11 +35,11 @@ pub fn parse_arguments(items: &[syn::NestedMetaItem]) -> Vec<Argument> {
3535
}
3636
arguments.push(Argument::Arg(ident.as_ref().to_owned(), None))
3737
}
38-
&syn::NestedMetaItem::MetaItem(syn::MetaItem::NameValue(ref ident, ref lit)) => {
39-
let name = ident.as_ref().to_owned();
40-
match lit {
41-
&syn::Lit::Str(ref s, _) => {
42-
if s == "*" { // #[args(args="*")]
38+
&syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) => {
39+
let name = nv.ident.as_ref().to_owned();
40+
match nv.lit {
41+
syn::Lit::Str(ref litstr) => {
42+
if litstr.value() == "*" { // #[args(args="*")]
4343
if has_kwargs {
4444
println!("* - syntax error, keyword arguments is defined: {:?}",
4545
args_str);
@@ -51,8 +51,7 @@ pub fn parse_arguments(items: &[syn::NestedMetaItem]) -> Vec<Argument> {
5151
}
5252
has_varargs = true;
5353
arguments.push(Argument::VarArgs(name));
54-
}
55-
else if s == "**" { // #[args(kwargs="**")]
54+
} else if litstr.value() == "**" { // #[args(kwargs="**")]
5655
if has_kwargs {
5756
println!("arguments already define ** (kw args): {:?}",
5857
args_str);
@@ -62,55 +61,55 @@ pub fn parse_arguments(items: &[syn::NestedMetaItem]) -> Vec<Argument> {
6261
arguments.push(Argument::KeywordArgs(name));
6362
} else {
6463
if has_varargs {
65-
arguments.push(Argument::Kwarg(name, s.clone()))
64+
arguments.push(Argument::Kwarg(name, litstr.value().clone()))
6665
} else {
6766
if has_kwargs {
6867
println!("syntax error, keyword arguments is defined: {:?}",
6968
args_str);
7069
return Vec::new()
7170
}
7271
has_kw = true;
73-
arguments.push(Argument::Arg(name, Some(s.clone())))
72+
arguments.push(Argument::Arg(name, Some(litstr.value().clone())))
7473
}
7574
}
7675
}
77-
&syn::Lit::Int(ref s, _) => {
76+
syn::Lit::Int(ref litint) => {
7877
if has_varargs {
79-
arguments.push(Argument::Kwarg(name, format!("{}", s)));
78+
arguments.push(Argument::Kwarg(name, format!("{}", litint.value())));
8079
} else {
8180
if has_kwargs {
8281
println!("syntax error, keyword arguments is defined: {:?}",
8382
args_str);
8483
return Vec::new()
8584
}
8685
has_kw = true;
87-
arguments.push(Argument::Arg(name, Some(format!("{}", s))));
86+
arguments.push(Argument::Arg(name, Some(format!("{}", litint.value()))));
8887
}
8988
}
90-
&syn::Lit::Bool(ref b) => {
89+
syn::Lit::Bool(ref litb) => {
9190
if has_varargs {
92-
arguments.push(Argument::Kwarg(name, format!("{}", b)));
91+
arguments.push(Argument::Kwarg(name, format!("{}", litb.value)));
9392
} else {
9493
if has_kwargs {
9594
println!("syntax error, keyword arguments is defined: {:?}",
9695
args_str);
9796
return Vec::new()
9897
}
9998
has_kw = true;
100-
arguments.push(Argument::Arg(name, Some(format!("{}", b))));
99+
arguments.push(Argument::Arg(name, Some(format!("{}", litb.value))));
101100
}
102101
}
103102
_ => {
104-
println!("Only string literal is supported, got: {:?}", lit);
103+
println!("Only string literal is supported, got: {:?}", nv.lit);
105104
return Vec::new()
106105
}
107106
}
108107
}
109-
&syn::NestedMetaItem::Literal(ref lit) => {
108+
&syn::NestedMeta::Literal(ref lit) => {
110109
match lit {
111-
&syn::Lit::Str(ref s, _) => {
110+
&syn::Lit::Str(ref lits) => {
112111
// #[args("*")]
113-
if s == "*" {
112+
if lits.value() == "*" {
114113
if has_kwargs {
115114
println!(
116115
"syntax error, keyword arguments is defined: {:?}",
@@ -127,7 +126,7 @@ pub fn parse_arguments(items: &[syn::NestedMetaItem]) -> Vec<Argument> {
127126
arguments.push(Argument::VarArgsSeparator);
128127
} else {
129128
println!("Unknown string literal, got: {:?} args: {:?}",
130-
s, args_str);
129+
lits.value(), args_str);
131130
return Vec::new()
132131
}
133132
}
@@ -154,11 +153,11 @@ mod test {
154153
use syn;
155154
use args::{Argument, parse_arguments};
156155

157-
fn items(s: &'static str) -> Vec<syn::NestedMetaItem> {
156+
fn items(s: &'static str) -> Vec<syn::NestedMeta> {
158157
let i = syn::parse_outer_attr(s).unwrap();
159158

160159
match i.value {
161-
syn::MetaItem::List(_, items) => {
160+
syn::Meta::List(_, items) => {
162161
items
163162
}
164163
_ => unreachable!()

0 commit comments

Comments
 (0)