Skip to content

Commit 845df6d

Browse files
lang/attribute/access-control: Allow multiple modifiers
1 parent d92cb15 commit 845df6d

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ incremented for features.
1111

1212
## [Unreleased]
1313

14+
### Features
15+
1416
* cli: Embed workspace programs into local validator genesis when testing.
1517
* cli: Stream program logs to `.anchor/program-logs` directory when testing.
1618
* spl: Add shared memory api.
19+
* lang/attribute/access-control: Allow specifying multiple modifier functions.
1720

1821
## [0.2.0] - 2021-02-08
1922

lang/attribute/access-control/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ proc-macro2 = "1.0"
1515
quote = "1.0"
1616
syn = { version = "=1.0.57", features = ["full"] }
1717
anyhow = "1.0.32"
18-
anchor-syn = { path = "../../syn", version = "0.2.0" }
18+
anchor-syn = { path = "../../syn", version = "0.2.0" }
19+
regex = "1.0"

lang/attribute/access-control/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ pub fn access_control(
5050
args: proc_macro::TokenStream,
5151
input: proc_macro::TokenStream,
5252
) -> proc_macro::TokenStream {
53-
let access_control: proc_macro2::TokenStream = args.to_string().parse().unwrap();
53+
let mut args = args.to_string();
54+
args.retain(|c| !c.is_whitespace());
55+
let access_control: Vec<proc_macro2::TokenStream> = args
56+
.split(')')
57+
.filter_map(|ac| match ac {
58+
"" => None,
59+
_ => Some(ac),
60+
})
61+
.map(|ac| format!("{})", ac)) // Put back on the split char.
62+
.map(|ac| format!("{}?;", ac)) // Add `?;` syntax.
63+
.map(|ac| ac.parse().unwrap())
64+
.collect();
5465

5566
let item_fn = parse_macro_input!(input as syn::ItemFn);
5667

@@ -63,7 +74,7 @@ pub fn access_control(
6374
proc_macro::TokenStream::from(quote! {
6475
#fn_vis #fn_sig {
6576

66-
#access_control?;
77+
#(#access_control)*
6778

6879
#(#fn_stmts)*
6980
}

0 commit comments

Comments
 (0)