{"thread":{"id":"51132","subject":"[PATCH v3] userdiff: add built-in pattern for rust","startedAt":"2019-05-20T17:04:08Z","lastAt":"2019-05-30T20:33:00Z","messageCount":9,"participants":["marcandre.lureau@redhat.com","Johannes Sixt","Marc-André Lureau","Junio C Hamano","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"375938","messageId":"20190520170403.16672-1-marcandre.lureau@redhat.com","threadId":"51132","inReplyTo":null,"subject":"[PATCH v3] userdiff: add built-in pattern for rust","fromName":"","fromEmail":"marcandre.lureau@redhat.com","sentAt":"2019-05-20T17:04:03Z","receivedAt":"2019-05-20T17:04:08Z","isPatch":true,"sender":{"key":"marcandre.lureau@redhat.com","avatar":null},"body":"From: Marc-André Lureau <mlureau@redhat.com>\n\nThis adds xfuncname and word_regex patterns for Rust, a quite\npopular programming language. It also includes test cases for the\nxfuncname regex (t4018) and updated documentation.\n\nThe word_regex pattern finds identifiers, integers, floats and\noperators, according to the Rust Reference Book.\n\nSigned-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>\n---\n Documentation/gitattributes.txt | 2 ++\n t/t4018-diff-funcname.sh        | 1 +\n t/t4018/rust-fn                 | 5 +++++\n t/t4018/rust-impl               | 5 +++++\n t/t4018/rust-struct             | 5 +++++\n t/t4018/rust-trait              | 5 +++++\n t/t4018/rust-unsafe             | 6 ++++++\n userdiff.c                      | 6 ++++++\n 8 files changed, 35 insertions(+)\n create mode 100644 t/t4018/rust-fn\n create mode 100644 t/t4018/rust-impl\n create mode 100644 t/t4018/rust-struct\n create mode 100644 t/t4018/rust-trait\n create mode 100644 t/t4018/rust-unsafe\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex 4fb20cd0e9..07da08fb27 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -833,6 +833,8 @@ patterns are available:\n \n - `ruby` suitable for source code in the Ruby language.\n \n+- `rust` suitable for source code in the Rust language.\n+\n - `tex` suitable for source code for LaTeX documents.\n \n \ndiff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh\nindex 22f9f88f0a..9261d6d3a0 100755\n--- a/t/t4018-diff-funcname.sh\n+++ b/t/t4018-diff-funcname.sh\n@@ -43,6 +43,7 @@ diffpatterns=\"\n \tphp\n \tpython\n \truby\n+\trust\n \ttex\n \tcustom1\n \tcustom2\ndiff --git a/t/t4018/rust-fn b/t/t4018/rust-fn\nnew file mode 100644\nindex 0000000000..cbe02155f1\n--- /dev/null\n+++ b/t/t4018/rust-fn\n@@ -0,0 +1,5 @@\n+pub(self) fn RIGHT<T>(x: &[T]) where T: Debug {\n+    let _ = x;\n+    // a comment\n+    let a = ChangeMe;\n+}\ndiff --git a/t/t4018/rust-impl b/t/t4018/rust-impl\nnew file mode 100644\nindex 0000000000..09df3cd93b\n--- /dev/null\n+++ b/t/t4018/rust-impl\n@@ -0,0 +1,5 @@\n+impl<'a, T: AsRef<[u8]>>  std::RIGHT for Git<'a> {\n+\n+    pub fn ChangeMe(&self) -> () {\n+    }\n+}\ndiff --git a/t/t4018/rust-struct b/t/t4018/rust-struct\nnew file mode 100644\nindex 0000000000..76aff1c0d8\n--- /dev/null\n+++ b/t/t4018/rust-struct\n@@ -0,0 +1,5 @@\n+#[derive(Debug)]\n+pub(super) struct RIGHT<'a> {\n+    name: &'a str,\n+    age: ChangeMe,\n+}\ndiff --git a/t/t4018/rust-trait b/t/t4018/rust-trait\nnew file mode 100644\nindex 0000000000..ea397f09ed\n--- /dev/null\n+++ b/t/t4018/rust-trait\n@@ -0,0 +1,5 @@\n+unsafe trait RIGHT<T> {\n+    fn len(&self) -> u32;\n+    fn ChangeMe(&self, n: u32) -> T;\n+    fn iter<F>(&self, f: F) where F: Fn(T);\n+}\ndiff --git a/t/t4018/rust-unsafe b/t/t4018/rust-unsafe\nnew file mode 100644\nindex 0000000000..fd4661a934\n--- /dev/null\n+++ b/t/t4018/rust-unsafe\n@@ -0,0 +1,6 @@\n+unsafe fn RIGHT(inc: u32) {\n+    unsafe {\n+        // don't catch unsafe block\n+        ChangeMe += inc;\n+    }\n+}\ndiff --git a/userdiff.c b/userdiff.c\nindex 3a78fbf504..e45b5920c6 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -130,6 +130,12 @@ PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n \t \"(@|@@|\\\\$)?[a-zA-Z_][a-zA-Z0-9_]*\"\n \t \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\\\?(\\\\\\\\C-)?(\\\\\\\\M-)?.\"\n \t \"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\\\.{1,3}|::|[!=]~\"),\n+PATTERNS(\"rust\",\n+\t \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t ]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t ]+)?(struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+[^;]*)$\",\n+\t /* -- */\n+\t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n+\t \"|[0-9][0-9_a-fA-Fiosuxz]*(\\\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?\"\n+\t \"|[-+*\\\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\\\|\\\\||->|=>|\\\\.{2}=|\\\\.{3}|::\"),\n PATTERNS(\"bibtex\", \"(@[a-zA-Z]{1,}[ \\t]*\\\\{{0,1}[ \\t]*[^ \\t\\\"@',\\\\#}{~%]*).*$\",\n \t \"[={}\\\"]|[^={}\\\" \\t]+\"),\n PATTERNS(\"tex\", \"^(\\\\\\\\((sub)*section|chapter|part)\\\\*{0,1}\\\\{.*)$\",\n\nbase-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6\n-- \n2.22.0.rc1.1.g079e7d2849.dirty\n\n"},{"id":"375951","messageId":"e1c4c2ab-927d-fff9-b9e7-13943cba2273@kdbg.org","threadId":"51132","inReplyTo":"20190520170403.16672-1-marcandre.lureau@redhat.com","subject":"Re: [PATCH v3] userdiff: add built-in pattern for rust","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-05-20T19:52:20Z","receivedAt":"2019-05-20T19:52:23Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 20.05.19 um 19:04 schrieb marcandre.lureau@redhat.com:\n> From: Marc-André Lureau <mlureau@redhat.com>\n> \n> This adds xfuncname and word_regex patterns for Rust, a quite\n> popular programming language. It also includes test cases for the\n> xfuncname regex (t4018) and updated documentation.\n> \n> The word_regex pattern finds identifiers, integers, floats and\n> operators, according to the Rust Reference Book.\n\nThis looks very good. I have a few questions regarding the hunk header\nregex.\n\n> diff --git a/userdiff.c b/userdiff.c\n> index 3a78fbf504..e45b5920c6 100644\n> --- a/userdiff.c\n> +++ b/userdiff.c\n> @@ -130,6 +130,12 @@ PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n>  \t \"(@|@@|\\\\$)?[a-zA-Z_][a-zA-Z0-9_]*\"\n>  \t \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\\\?(\\\\\\\\C-)?(\\\\\\\\M-)?.\"\n>  \t \"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\\\.{1,3}|::|[!=]~\"),\n> +PATTERNS(\"rust\",\n> +\t \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t ]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t ]+)?(struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+[^;]*)$\",\n\nThis pattern matches only if there is no semicolon behind the signal\nwords on the line. Is that important? Can you show a (test) case where a\nline with a semicolon would be picked incorrectly if '[^;]*' were\nsimplified to '.*'?\n\nYou permit whitespace at the beginning of an anchor line. I guess that\nis to catch nested definitions. Or is it common style to write indented\ncode? Can you show a test case where this makes sense?\n\nWould it be sufficient to simplify\n\n    (struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+\nto\n    (struct|enum|union|mod|trait|fn|impl)[< \\t]+\n\nas it is only important to exclude identifiers that start with these\nkeywords.\n\n> +\t /* -- */\n> +\t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> +\t \"|[0-9][0-9_a-fA-Fiosuxz]*(\\\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?\"\n> +\t \"|[-+*\\\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\\\|\\\\||->|=>|\\\\.{2}=|\\\\.{3}|::\"),\n>  PATTERNS(\"bibtex\", \"(@[a-zA-Z]{1,}[ \\t]*\\\\{{0,1}[ \\t]*[^ \\t\\\"@',\\\\#}{~%]*).*$\",\n>  \t \"[={}\\\"]|[^={}\\\" \\t]+\"),\n>  PATTERNS(\"tex\", \"^(\\\\\\\\((sub)*section|chapter|part)\\\\*{0,1}\\\\{.*)$\",\n> \n> base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6\n\n-- Hannes\n"},{"id":"375987","messageId":"CAMxuvay3ynFuP3fu57T0f9NEhjbCfM2hCUrdBHvxw-d1Jj54FA@mail.gmail.com","threadId":"51132","inReplyTo":"e1c4c2ab-927d-fff9-b9e7-13943cba2273@kdbg.org","subject":"Re: [PATCH v3] userdiff: add built-in pattern for rust","fromName":"Marc-André Lureau","fromEmail":"marcandre.lureau@redhat.com","sentAt":"2019-05-21T10:57:12Z","receivedAt":"2019-05-21T10:57:26Z","isPatch":true,"sender":{"key":"marcandre.lureau@redhat.com","avatar":null},"body":"Hi\n\nOn Mon, May 20, 2019 at 9:52 PM Johannes Sixt <j6t@kdbg.org> wrote:\n>\n> Am 20.05.19 um 19:04 schrieb marcandre.lureau@redhat.com:\n> > From: Marc-André Lureau <mlureau@redhat.com>\n> >\n> > This adds xfuncname and word_regex patterns for Rust, a quite\n> > popular programming language. It also includes test cases for the\n> > xfuncname regex (t4018) and updated documentation.\n> >\n> > The word_regex pattern finds identifiers, integers, floats and\n> > operators, according to the Rust Reference Book.\n>\n> This looks very good. I have a few questions regarding the hunk header\n> regex.\n>\n> > diff --git a/userdiff.c b/userdiff.c\n> > index 3a78fbf504..e45b5920c6 100644\n> > --- a/userdiff.c\n> > +++ b/userdiff.c\n> > @@ -130,6 +130,12 @@ PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n> >        \"(@|@@|\\\\$)?[a-zA-Z_][a-zA-Z0-9_]*\"\n> >        \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\\\?(\\\\\\\\C-)?(\\\\\\\\M-)?.\"\n> >        \"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\\\.{1,3}|::|[!=]~\"),\n> > +PATTERNS(\"rust\",\n> > +      \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t ]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t ]+)?(struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+[^;]*)$\",\n>\n> This pattern matches only if there is no semicolon behind the signal\n> words on the line. Is that important? Can you show a (test) case where a\n> line with a semicolon would be picked incorrectly if '[^;]*' were\n> simplified to '.*'?\n\n\nOk, I am adding:\n\ntrait RIGHT {\n\n    fn new(name: &'static str) -> Self;\n\n    fn ChangeMe(&self) {\n        // should skip \"new\", and return trait name\n    }\n}\n\n> You permit whitespace at the beginning of an anchor line. I guess that\n> is to catch nested definitions. Or is it common style to write indented\n> code? Can you show a test case where this makes sense?\n>\n\nsure, I thought it was already covered.\n\nfn foo() {\n    fn RIGHT() {\n        // must catch nested function\n        ChangeMe;\n    }\n}\n\n(a simpler example would be a method implementation)\n\n> Would it be sufficient to simplify\n>\n>     (struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+\n> to\n>     (struct|enum|union|mod|trait|fn|impl)[< \\t]+\n>\n> as it is only important to exclude identifiers that start with these\n> keywords.\n\nI think that would be fine, ok I am changing it\n\n>\n> > +      /* -- */\n> > +      \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> > +      \"|[0-9][0-9_a-fA-Fiosuxz]*(\\\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?\"\n> > +      \"|[-+*\\\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\\\|\\\\||->|=>|\\\\.{2}=|\\\\.{3}|::\"),\n> >  PATTERNS(\"bibtex\", \"(@[a-zA-Z]{1,}[ \\t]*\\\\{{0,1}[ \\t]*[^ \\t\\\"@',\\\\#}{~%]*).*$\",\n> >        \"[={}\\\"]|[^={}\\\" \\t]+\"),\n> >  PATTERNS(\"tex\", \"^(\\\\\\\\((sub)*section|chapter|part)\\\\*{0,1}\\\\{.*)$\",\n> >\n> > base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6\n>\n> -- Hannes\n"},{"id":"376316","messageId":"xmqqtvde4jxv.fsf@gitster-ct.c.googlers.com","threadId":"51132","inReplyTo":"CAMxuvay3ynFuP3fu57T0f9NEhjbCfM2hCUrdBHvxw-d1Jj54FA@mail.gmail.com","subject":"Re: [PATCH v3] userdiff: add built-in pattern for rust","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-05-28T16:34:20Z","receivedAt":"2019-05-28T16:34:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marc-André Lureau <marcandre.lureau@redhat.com> writes:\n\n> Ok, I am adding:\n> ...\n> sure, I thought it was already covered.\n> ...\n> I think that would be fine, ok I am changing it\n\nThanks, both.\n\nThe previous round has already hit 'next' (which means that we won't\nreplacing the patch wholesale), so whatever you do, please make the\nupdate relative to / on top of what is queued as d74e7860\n(\"userdiff: add built-in pattern for rust\", 2019-05-17).\n\n\n"},{"id":"376349","messageId":"a7d42d82-7d84-bf25-55ce-5c57a7ce70e9@kdbg.org","threadId":"51132","inReplyTo":"xmqqtvde4jxv.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v3] userdiff: add built-in pattern for rust","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-05-28T20:31:25Z","receivedAt":"2019-05-28T20:31:29Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 28.05.19 um 18:34 schrieb Junio C Hamano:\n> Marc-André Lureau <marcandre.lureau@redhat.com> writes:\n> \n>> Ok, I am adding:\n>> ...\n>> sure, I thought it was already covered.\n>> ...\n>> I think that would be fine, ok I am changing it\n> \n> Thanks, both.\n> \n> The previous round has already hit 'next' (which means that we won't\n> replacing the patch wholesale), so whatever you do, please make the\n> update relative to / on top of what is queued as d74e7860\n> (\"userdiff: add built-in pattern for rust\", 2019-05-17).\n\nOk. So, Marc-André, would you mind resending an incremental patch,\nbecause the word-regexp that is currently in 'next' would catch certain\nexpressions that should be multiple words as a single word?\n\n-- Hannes\n"},{"id":"376357","messageId":"CAMxuvaxW9fc4ft=aERSUt4+n237bdtDpKJMvyKq=H7yz-VLWbg@mail.gmail.com","threadId":"51132","inReplyTo":"a7d42d82-7d84-bf25-55ce-5c57a7ce70e9@kdbg.org","subject":"Re: [PATCH v3] userdiff: add built-in pattern for rust","fromName":"Marc-André Lureau","fromEmail":"marcandre.lureau@redhat.com","sentAt":"2019-05-28T21:01:27Z","receivedAt":"2019-05-28T21:01:41Z","isPatch":true,"sender":{"key":"marcandre.lureau@redhat.com","avatar":null},"body":"Hi Johannes\n\nOn Tue, May 28, 2019 at 10:31 PM Johannes Sixt <j6t@kdbg.org> wrote:\n>\n> Am 28.05.19 um 18:34 schrieb Junio C Hamano:\n> > Marc-André Lureau <marcandre.lureau@redhat.com> writes:\n> >\n> >> Ok, I am adding:\n> >> ...\n> >> sure, I thought it was already covered.\n> >> ...\n> >> I think that would be fine, ok I am changing it\n> >\n> > Thanks, both.\n> >\n> > The previous round has already hit 'next' (which means that we won't\n> > replacing the patch wholesale), so whatever you do, please make the\n> > update relative to / on top of what is queued as d74e7860\n> > (\"userdiff: add built-in pattern for rust\", 2019-05-17).\n>\n> Ok. So, Marc-André, would you mind resending an incremental patch,\n> because the word-regexp that is currently in 'next' would catch certain\n> expressions that should be multiple words as a single word?\n\nBeside a few extras tests, the diff is:\n\n@@ -134,11 +134,10 @@ PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n         \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\\\?(\\\\\\\\C-)?(\\\\\\\\M-)?.\"\n         \"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\\\.{1,3}|::|[!=]~\"),\n PATTERNS(\"rust\",\n-        \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t\n]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t\n]+)?(struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+[^;]*)$\",\n+        \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t\n]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t\n]+)?(struct|enum|union|mod|trait|fn|impl)[< \\t]+[^;]*)$\",\n         /* -- */\n         \"[a-zA-Z_][a-zA-Z0-9_]*\"\n-        \"|[-+_0-9.eE]+(f32|f64|u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize)?\"\n-        \"|0[box]?[0-9a-fA-F_]+(u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize)?\"\n+        \"|[0-9][0-9_a-fA-Fiosuxz]*(\\\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?\"\n         \"|[-+*\\\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\\\|\\\\||->|=>|\\\\.{2}=|\\\\.{3}|::\"),\n\nSo it is simplifying handling of type parameters, and lowering the\ncomplexity of literal numbers.\n\nBoth of these changes were based on your recommendations. Would you\nmind sending a follow-up patch yourself?\n\nI can send a seperate patch for the 3 extra tests.\n\nthanks\n"},{"id":"376445","messageId":"2d32b107-9278-faa0-4fea-afe662031272@kdbg.org","threadId":"51132","inReplyTo":"CAMxuvaxW9fc4ft=aERSUt4+n237bdtDpKJMvyKq=H7yz-VLWbg@mail.gmail.com","subject":"[PATCH] userdiff: two simplifications of patterns for rust","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-05-30T16:44:35Z","receivedAt":"2019-05-30T16:44:40Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"- Do not enforce (but assume) syntactic correctness of language\n  constructs that go into hunk headers: we only want to ensure that\n  the keywords actually are words and not just the initial part of\n  some identifier.\n\n- In the word regex, match numbers only when they begin with a digit,\n  but then be liberal in what follows, assuming that the text that is\n  matched is syntactially correct.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\n---\nAm 28.05.19 um 23:01 schrieb Marc-André Lureau:\n> Both of these changes were based on your recommendations. Would you\n> mind sending a follow-up patch yourself?\n> \n> I can send a seperate patch for the 3 extra tests.\n\nSo, here it is. Looking forward to seeing a patch with the tests.\n\n userdiff.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/userdiff.c b/userdiff.c\nindex 8d7e62e2a5..2bcf105caf 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -131,11 +131,10 @@ PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n \t \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\\\?(\\\\\\\\C-)?(\\\\\\\\M-)?.\"\n \t \"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\\\.{1,3}|::|[!=]~\"),\n PATTERNS(\"rust\",\n-\t \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t ]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t ]+)?(struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \\t]+[^;]*)$\",\n+\t \"^[\\t ]*((pub(\\\\([^\\\\)]+\\\\))?[\\t ]+)?((async|const|unsafe|extern([\\t ]+\\\"[^\\\"]+\\\"))[\\t ]+)?(struct|enum|union|mod|trait|fn|impl)[< \\t]+[^;]*)$\",\n \t /* -- */\n \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n-\t \"|[-+_0-9.eE]+(f32|f64|u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize)?\"\n-\t \"|0[box]?[0-9a-fA-F_]+(u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize)?\"\n+\t \"|[0-9][0-9_a-fA-Fiosuxz]*(\\\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?\"\n \t \"|[-+*\\\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\\\|\\\\||->|=>|\\\\.{2}=|\\\\.{3}|::\"),\n PATTERNS(\"bibtex\", \"(@[a-zA-Z]{1,}[ \\t]*\\\\{{0,1}[ \\t]*[^ \\t\\\"@',\\\\#}{~%]*).*$\",\n \t \"[={}\\\"]|[^={}\\\" \\t]+\"),\n-- \n2.21.0.285.gc38d92e052\n"},{"id":"376452","messageId":"875zprn4zr.fsf@evledraar.gmail.com","threadId":"51132","inReplyTo":"2d32b107-9278-faa0-4fea-afe662031272@kdbg.org","subject":"Re: [PATCH] userdiff: two simplifications of patterns for rust","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-05-30T18:59:04Z","receivedAt":"2019-05-30T18:59:08Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, May 30 2019, Johannes Sixt wrote:\n\n> - Do not enforce (but assume) syntactic correctness of language\n>   constructs that go into hunk headers: we only want to ensure that\n>   the keywords actually are words and not just the initial part of\n>   some identifier.\n>\n> - In the word regex, match numbers only when they begin with a digit,\n>   but then be liberal in what follows, assuming that the text that is\n>   matched is syntactially correct.\n\nI don't know if this is possible for Rust (but very much suspect so...),\nbut I think that in general we should aim to be more forgiving than not\nwith these patterns.\n\nBecause, as the history of userdiff.c shows, new keywords get introduced\ninto these languages, and old git versions survive for a long time. If\nthe syntax is otherwise fairly regular perhaps we don't need to hardcode\nthe list of existing keywords?\n"},{"id":"376458","messageId":"e898920d-46bf-781a-de2f-6452bf5bae05@kdbg.org","threadId":"51132","inReplyTo":"875zprn4zr.fsf@evledraar.gmail.com","subject":"Re: [PATCH] userdiff: two simplifications of patterns for rust","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-05-30T20:32:56Z","receivedAt":"2019-05-30T20:33:00Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 30.05.19 um 20:59 schrieb Ævar Arnfjörð Bjarmason:\n> \n> On Thu, May 30 2019, Johannes Sixt wrote:\n> \n>> - Do not enforce (but assume) syntactic correctness of language\n>>   constructs that go into hunk headers: we only want to ensure that\n>>   the keywords actually are words and not just the initial part of\n>>   some identifier.\n>>\n>> - In the word regex, match numbers only when they begin with a digit,\n>>   but then be liberal in what follows, assuming that the text that is\n>>   matched is syntactially correct.\n> \n> I don't know if this is possible for Rust (but very much suspect so...),\n> but I think that in general we should aim to be more forgiving than not\n> with these patterns.\n\nThe C/C++ pattern is actually very forgiving in the hunk header pattern:\nIt takes every line that begins with an un-indented letter. That works\nvery well in in C because C does not have nested functions and it is\ntypical that the function definition lines are not indented. But that\nbreaks down with C++: indented function definitions are very common;\nthey happen inside class and namespace definitions. Such functions are\nnot picked up, and we live with that so far (at least, I do).\n\n> Because, as the history of userdiff.c shows, new keywords get introduced\n> into these languages, and old git versions survive for a long time. If\n> the syntax is otherwise fairly regular perhaps we don't need to hardcode\n> the list of existing keywords?\n\nWe are talking about (1) hunk header lines (not something really\nimportant) and (2) programming languages: new keywords don't pop up\nevery month. Granted, inventing new languages is en vogue these days.\nBut really, I mean, WTH?\n\nHaving available keywords to recognize hunk header candidates helps a\nlot. I thought long about a possible pattern for C++, but I gave up,\nbecause the language is so rich and there are no suitable keywords.\n\n-- Hannes\n"}]}