git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] userdiff: support Rust macros

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Oct 6, 2020, 16:44 UTC
Message-ID
<18297f15-3b67-73a6-9ad4-cf477622fe62@gmail.com>
In-Reply-To
<pull.865.git.git.1601986430388.gitgitgadget@gmail.com>
Hi Konrad
Thanks for the patch, this would be a useful addition
On 06/10/2020 13:13, Konrad Borowski via GitGitGadget wrote:
Show 40 quoted lines
> From: Konrad Borowski <konrad@borowski.pw>
> 
> This adds a support for macro_rules! keyword which declares
> a macro. It also includes a test case.
> 
> Signed-off-by: Konrad Borowski <konrad@borowski.pw>
> ---
>      userdiff: support Rust macros
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-865%2Fxfix%2Fuserdiff-macro-rules-rust-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-865/xfix/userdiff-macro-rules-rust-v1
> Pull-Request: https://github.com/git/git/pull/865
> 
>   t/t4018/rust-macro-rules | 6 ++++++
>   userdiff.c               | 2 +-
>   2 files changed, 7 insertions(+), 1 deletion(-)
>   create mode 100644 t/t4018/rust-macro-rules
> 
> diff --git a/t/t4018/rust-macro-rules b/t/t4018/rust-macro-rules
> new file mode 100644
> index 0000000000..ec610c5b62
> --- /dev/null
> +++ b/t/t4018/rust-macro-rules
> @@ -0,0 +1,6 @@
> +macro_rules! RIGHT {
> +    () => {
> +        // a comment
> +        let x = ChangeMe;
> +    };
> +}
> diff --git a/userdiff.c b/userdiff.c
> index fde02f225b..f13a913697 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -165,7 +165,7 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
>   	 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
>   	 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
>   PATTERNS("rust",
> -	 "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl)[< \t]+[^;]*)$",
> +	 "^[\t ]*(((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl)[< \t]+|macro_rules[\t ]*!)

I think you want the `!` before the `[\t ]`. We could probably get away with just adding `macro-rules!` as another alternative in the group starting with `struct`

Best Wishes
Phillip
[^;]*)$",
Show 6 quoted lines
>   	 /* -- */
>   	 "[a-zA-Z_][a-zA-Z0-9_]*"
>   	 "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"
> 
> base-commit: d98273ba77e1ab9ec755576bc86c716a97bf59d7
> 
Previous: Konrad Borowski via GitGitGadgetNext: Johannes Sixt
Message 2 of 6 in “userdiff: support Rust macros”
  1. userdiff: support Rust macrosKonrad Borowski via GitGitGadget, Oct 6, 2020
  2. Phillip WoodOct 6, 2020
  3. Johannes SixtOct 6, 2020
  4. userdiff: permit Rust's macro_rules! keyword in hunk headersKonrad Borowski via GitGitGadget, Oct 7, 2020
  5. Junio C HamanoOct 7, 2020
  6. userdiff: recognize 'macro_rules!' as starting a Rust function blockKonrad Borowski via GitGitGadget, Oct 7, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.