{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/58237003","id":58237003,"diff_hunk":"@@ -0,0 +1,417 @@\n+- Feature Name: procedural_macros\n+- Start Date: 2016-02-15\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+# Summary\n+[summary]: #summary\n+\n+This RFC proposes an evolution of Rust's procedural macro system (aka syntax\n+extensions, aka compiler plugins). This RFC specifies syntax for the definition\n+of procedural macros, a high-level view of their implementation in the compiler,\n+and outlines how they interact with the compilation process.\n+\n+This RFC specifies the architecture of the procedural macro system. It relies on\n+[RFC 1561](https://github.com/rust-lang/rfcs/pull/1561) which specifies the\n+naming and modularisation of macros. It leaves many of the details for further\n+RFCs, in particular the details of the APIs available to macro authors\n+(tentatively called `libmacro`). See this [blog post](http://ncameron.org/blog/libmacro/)\n+for some ideas of how that might look.\n+\n+At the highest level, macros are defined by implementing functions marked with\n+a `#[macro]` attribute. Macros operate on a list of tokens provided by the\n+compiler and return a list of tokens that the macro use is replaced by. We\n+provide low-level facilities for operating on these tokens. Higher level\n+facilities (e.g., for parsing tokens to an AST) should exist as library crates.\n+\n+\n+# Motivation\n+[motivation]: #motivation\n+\n+Procedural macros have long been a part of Rust and have been used for diverse\n+and interesting purposes, for example [compile-time regexes](https://github.com/rust-lang-nursery/regex),\n+[serialisation](https://github.com/serde-rs/serde), and\n+[design by contract](https://github.com/nrc/libhoare). They allow the ultimate\n+flexibility in syntactic abstraction, and offer possibilities for efficiently\n+using Rust in novel ways.\n+\n+Procedural macros are currently unstable and are awkward to define. We would\n+like to remedy this by implementing a new, simpler system for procedural macros,\n+and for this new system to be on the usual path to stabilisation.\n+\n+One major problem with the current system is that since it is based on ASTs, if\n+we change the Rust language (even in a backwards compatible way) we can easily\n+break procedural macros. Therefore, offering the usual backwards compatibility\n+guarantees to procedural macros, would inhibit our ability to evolve the\n+language. By switching to a token-based (rather than AST- based) system, we hope\n+to avoid this problem.\n+\n+# Detailed design\n+[design]: #detailed-design\n+\n+There are two kinds of procedural macro: function-like and macro-like. These two\n+kinds exist today, and other than naming (see\n+[RFC 1561](https://github.com/rust-lang/rfcs/pull/1561)) the syntax for using\n+these macros remains unchanged. If the macro is called `foo`, then a function-\n+like macro is used with syntax `foo!(...)`, and an attribute-like macro with\n+`#[foo(...)] ...`. Macros may be used in the same places as `macro_rules` macros\n+and this remains unchanged.\n+\n+To define a procedural macro, the programmer must write a function with a\n+specific signature and attribute. Where `foo` is the name of a function-like\n+macro:\n+\n+```\n+#[macro]\n+pub fn foo(TokenStream, &mut MacroContext) -> TokenStream;","path":"text/0000-proc-macros.md","position":66,"original_position":66,"commit_id":"9c42f45387d979c3af1bf1afe4b33659ca7e1c63","original_commit_id":"9c42f45387d979c3af1bf1afe4b33659ca7e1c63","user":{"login":"seanmonstar","id":51479,"avatar_url":"https://avatars.githubusercontent.com/u/51479?v=3","gravatar_id":"","url":"https://api.github.com/users/seanmonstar","html_url":"https://github.com/seanmonstar","followers_url":"https://api.github.com/users/seanmonstar/followers","following_url":"https://api.github.com/users/seanmonstar/following{/other_user}","gists_url":"https://api.github.com/users/seanmonstar/gists{/gist_id}","starred_url":"https://api.github.com/users/seanmonstar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanmonstar/subscriptions","organizations_url":"https://api.github.com/users/seanmonstar/orgs","repos_url":"https://api.github.com/users/seanmonstar/repos","events_url":"https://api.github.com/users/seanmonstar/events{/privacy}","received_events_url":"https://api.github.com/users/seanmonstar/received_events","type":"User","site_admin":false},"body":"Alternative: use the `macro` keyword (it was reserved in 1.0). It would make it feel more part of the language, in my opinion.\r\n\r\n```rust\r\npub macro foo(TokenStream, &mut MacroContext) -> TokenStream;\r\n```","created_at":"2016-04-01T17:19:00Z","updated_at":"2016-04-01T17:19:00Z","html_url":"https://github.com/rust-lang/rfcs/pull/1566#discussion_r58237003","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/58237003"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1566#discussion_r58237003"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566","id":64916315,"html_url":"https://github.com/rust-lang/rfcs/pull/1566","diff_url":"https://github.com/rust-lang/rfcs/pull/1566.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/1566.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1566","number":1566,"state":"open","locked":false,"title":"Procedural macros","user":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"body":"This RFC proposes an evolution of Rust's procedural macro system (aka syntax\r\nextensions, aka compiler plugins). This RFC specifies syntax for the definition\r\nof procedural macros, a high-level view of their implementation in the compiler,\r\nand outlines how they interact with the compilation process.\r\n\r\nAt the highest level, macros are defined by implementing functions marked with\r\na `#[macro]` attribute. Macros operate on a list of tokens provided by the\r\ncompiler and return a list of tokens that the macro use is replaced by. We\r\nprovide low-level facilities for operating on these tokens. Higher level\r\nfacilities (e.g., for parsing tokens to an AST) should exist as library crates.","created_at":"2016-04-01T09:16:43Z","updated_at":"2016-04-01T17:19:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ade706bfb28cefcb8230d87cccf2fe48f792d2d4","assignee":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1566/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/9c42f45387d979c3af1bf1afe4b33659ca7e1c63","head":{"label":"nrc:proc-macros","ref":"proc-macros","sha":"9c42f45387d979c3af1bf1afe4b33659ca7e1c63","user":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"repo":{"id":17579664,"name":"rfcs","full_name":"nrc/rfcs","owner":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nrc/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/nrc/rfcs","forks_url":"https://api.github.com/repos/nrc/rfcs/forks","keys_url":"https://api.github.com/repos/nrc/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nrc/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nrc/rfcs/teams","hooks_url":"https://api.github.com/repos/nrc/rfcs/hooks","issue_events_url":"https://api.github.com/repos/nrc/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/nrc/rfcs/events","assignees_url":"https://api.github.com/repos/nrc/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/nrc/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/nrc/rfcs/tags","blobs_url":"https://api.github.com/repos/nrc/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nrc/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nrc/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/nrc/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nrc/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/nrc/rfcs/languages","stargazers_url":"https://api.github.com/repos/nrc/rfcs/stargazers","contributors_url":"https://api.github.com/repos/nrc/rfcs/contributors","subscribers_url":"https://api.github.com/repos/nrc/rfcs/subscribers","subscription_url":"https://api.github.com/repos/nrc/rfcs/subscription","commits_url":"https://api.github.com/repos/nrc/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/nrc/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/nrc/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/nrc/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/nrc/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/nrc/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nrc/rfcs/merges","archive_url":"https://api.github.com/repos/nrc/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nrc/rfcs/downloads","issues_url":"https://api.github.com/repos/nrc/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/nrc/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/nrc/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/nrc/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nrc/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/nrc/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/nrc/rfcs/deployments","created_at":"2014-03-10T02:38:22Z","updated_at":"2016-02-03T09:16:43Z","pushed_at":"2016-04-01T09:15:17Z","git_url":"git://github.com/nrc/rfcs.git","ssh_url":"git@github.com:nrc/rfcs.git","clone_url":"https://github.com/nrc/rfcs.git","svn_url":"https://github.com/nrc/rfcs","homepage":"","size":2623,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"cbe92f4a3fbc956bd75dacf1ea2e14ef84d2bdb1","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rfcs/deployments","created_at":"2014-03-07T21:29:00Z","updated_at":"2016-03-30T22:16:46Z","pushed_at":"2016-04-01T16:53:19Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"","size":5212,"stargazers_count":585,"watchers_count":585,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":291,"mirror_url":null,"open_issues_count":649,"forks":291,"open_issues":649,"watchers":585,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1566"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1566"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1566/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1566/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/9c42f45387d979c3af1bf1afe4b33659ca7e1c63"}}}}