The Wayback Machine - https://web.archive.org/web/20210913224052/https://github.com/rune-rs/rune/issues/43
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support attributes #43

Open
1 of 2 tasks
udoprog opened this issue Sep 9, 2020 · 2 comments
Open
1 of 2 tasks

Support attributes #43

udoprog opened this issue Sep 9, 2020 · 2 comments

Comments

@udoprog
Copy link
Task lists! Give feedback
Collaborator

@udoprog udoprog commented Sep 9, 2020

Support rust style attributes;

#[hello]
fn test() {
}

#[hello]
struct Foo {
}

This will be invoked as macros with the ast of the thing that it annotates as input, and anything produced by the macro will be appended to the source (to work the same as Rust procedural macros).

  • Implement parsing (#83).
  • Add compiler support to process attributes.

Implementation note: If you need inspiration for how to structure the AST, look into Attribute in the syn project.

@killercup
Copy link
Contributor

@killercup killercup commented Sep 12, 2020

FYI, this is one of the main things I dislike in Rust's syntax because of the typing overhead and the fact that pretty much any tokens are valid in #[here]. Using @Foo(param=foo) (or #[Foo(param=foo)] if you like typing braces) and supporting exactly this style of calling a macro would reduce complexity quite a bit.

@udoprog
Copy link
Collaborator Author

@udoprog udoprog commented Sep 16, 2020

FYI, this is one of the main things I dislike in Rust's syntax because of the typing overhead and the fact that pretty much any tokens are valid in #[here]. Using @Foo(param=foo) (or #[Foo(param=foo)] if you like typing braces) and supporting exactly this style of calling a macro would reduce complexity quite a bit.

I appreciate the point of view. But this is another instance when I want to maintain feature parity with Rust to make it possible to more easily transfer ideas. A note is that attributes are pretty much macro calls with different call syntax (and are associated with the AST they are tacked on to). You can see this in syn, with the Macro (macro call) and Attribute. They both take a Path and a raw TokenStream.

syn also provides a convenience function to parse its content as meta items. Something like this can be done to unobtrusively enforce more opinion. Or something like darling can be ported to Rune.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants