git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Konrad Borowski via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Phillip Wood <phillip.wood123@gmail.com>,
	Johannes Sixt <j6t@kdbg.org>,
	Konrad Borowski <github@borowski.pw>,
	Konrad Borowski <konrad@borowski.pw>
Subject: [PATCH v3] userdiff: recognize 'macro_rules!' as starting a Rust function block
Date: Wed, 07 Oct 2020 13:26:11 +0000	[thread overview]
Message-ID: <pull.865.v3.git.git.1602077171751.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.865.v2.git.git.1602048429067.gitgitgadget@gmail.com>

From: Konrad Borowski <konrad@borowski.pw>

Signed-off-by: Konrad Borowski <konrad@borowski.pw>
---
    userdiff: support Rust macros
    
    Changes since v1:
    
     * Changed macro_rules! to be considered to use the same rule as rest of
       keywords to reduce the size of a change as suggested by Phillip Wood.
       This means that 'pub macro_rules!` (a syntax error) is considered to
       be a hunk header.
     * Written commit message in imperative mood as suggested by Johannes
       Sixt.
    
    Changes since v2:
    
     * Updated the commit message as suggested by Junio C Hamano.
     * Removed handling for 'macro_rules !' with a space in-between tokens.
       While it is allowed by the compiler to have a space between
       'macro_rules' and '!' it's pretty much never done.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-865%2Fxfix%2Fuserdiff-macro-rules-rust-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-865/xfix/userdiff-macro-rules-rust-v3
Pull-Request: https://github.com/git/git/pull/865

Range-diff vs v2:

 1:  a3fd67d84f ! 1:  0d8e6e06d4 userdiff: permit Rust's macro_rules! keyword in hunk headers
     @@ Metadata
      Author: Konrad Borowski <konrad@borowski.pw>
      
       ## Commit message ##
     -    userdiff: permit Rust's macro_rules! keyword in hunk headers
     -
     -    Changes since v1:
     -    - Changed macro_rules! to be considered to use the same
     -      rule as rest of keywords to reduce the size of a change
     -      as suggested by Phillip Wood. This means that
     -      'pub macro_rules!` (a syntax error) is considered to be
     -      a hunk header.
     -
     -    - Written commit message in imperative mood as suggested by
     -      Johannes Sixt.
     +    userdiff: recognize 'macro_rules!' as starting a Rust function block
      
          Signed-off-by: Konrad Borowski <konrad@borowski.pw>
      
     @@ userdiff.c: PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
       	 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{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|macro_rules[\t ]*!)[< \t]+[^;]*)$",
     ++	 "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$",
       	 /* -- */
       	 "[a-zA-Z_][a-zA-Z0-9_]*"
       	 "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"


 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..2903037724 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|macro_rules!)[< \t]+[^;]*)$",
 	 /* -- */
 	 "[a-zA-Z_][a-zA-Z0-9_]*"
 	 "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"

base-commit: d98273ba77e1ab9ec755576bc86c716a97bf59d7
-- 
gitgitgadget

      parent reply	other threads:[~2020-10-07 13:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 12:13 [PATCH] userdiff: support Rust macros Konrad Borowski via GitGitGadget
2020-10-06 16:44 ` Phillip Wood
2020-10-06 18:44 ` Johannes Sixt
2020-10-07  5:27 ` [PATCH v2] userdiff: permit Rust's macro_rules! keyword in hunk headers Konrad Borowski via GitGitGadget
2020-10-07  6:10   ` Junio C Hamano
2020-10-07 13:26   ` Konrad Borowski via GitGitGadget [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.865.v3.git.git.1602077171751.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=github@borowski.pw \
    --cc=j6t@kdbg.org \
    --cc=konrad@borowski.pw \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).