Skip to content

Commit

Permalink
lang/attribute/access-control: Allow multiple modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Feb 10, 2021
1 parent d92cb15 commit 845df6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ incremented for features.

## [Unreleased]

### Features

* cli: Embed workspace programs into local validator genesis when testing.
* cli: Stream program logs to `.anchor/program-logs` directory when testing.
* spl: Add shared memory api.
* lang/attribute/access-control: Allow specifying multiple modifier functions.

## [0.2.0] - 2021-02-08

Expand Down
3 changes: 2 additions & 1 deletion lang/attribute/access-control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "=1.0.57", features = ["full"] }
anyhow = "1.0.32"
anchor-syn = { path = "../../syn", version = "0.2.0" }
anchor-syn = { path = "../../syn", version = "0.2.0" }
regex = "1.0"
15 changes: 13 additions & 2 deletions lang/attribute/access-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ pub fn access_control(
args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let access_control: proc_macro2::TokenStream = args.to_string().parse().unwrap();
let mut args = args.to_string();
args.retain(|c| !c.is_whitespace());
let access_control: Vec<proc_macro2::TokenStream> = args
.split(')')
.filter_map(|ac| match ac {
"" => None,
_ => Some(ac),
})
.map(|ac| format!("{})", ac)) // Put back on the split char.
.map(|ac| format!("{}?;", ac)) // Add `?;` syntax.
.map(|ac| ac.parse().unwrap())
.collect();

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

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

#access_control?;
#(#access_control)*

#(#fn_stmts)*
}
Expand Down

0 comments on commit 845df6d

Please sign in to comment.