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

Re: [PATCH v3] userdiff: add built-in pattern for rust

From
Johannes Sixt <j6t@kdbg.org>
Date
May 20, 2019, 19:52 UTC
Message-ID
<e1c4c2ab-927d-fff9-b9e7-13943cba2273@kdbg.org>
In-Reply-To
<20190520170403.16672-1-marcandre.lureau@redhat.com>
Am 20.05.19 um 19:04 schrieb marcandre.lureau@redhat.com:
Show 8 quoted lines
> From: Marc-André Lureau <mlureau@redhat.com>
> 
> This adds xfuncname and word_regex patterns for Rust, a quite
> popular programming language. It also includes test cases for the
> xfuncname regex (t4018) and updated documentation.
> 
> The word_regex pattern finds identifiers, integers, floats and
> operators, according to the Rust Reference Book.

This looks very good. I have a few questions regarding the hunk header regex.

Show 10 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index 3a78fbf504..e45b5920c6 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -130,6 +130,12 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
>  	 "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
>  	 "|[-+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]+[^;]*)$",

This pattern matches only if there is no semicolon behind the signal words on the line. Is that important? Can you show a (test) case where a line with a semicolon would be picked incorrectly if '[^;]*' were simplified to '.*'?

You permit whitespace at the beginning of an anchor line. I guess that is to catch nested definitions. Or is it common style to write indented code? Can you show a test case where this makes sense?

Would it be sufficient to simplify
    (struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \t]+
to
    (struct|enum|union|mod|trait|fn|impl)[< \t]+

as it is only important to exclude identifiers that start with these keywords.

Show 9 quoted lines
> +	 /* -- */
> +	 "[a-zA-Z_][a-zA-Z0-9_]*"
> +	 "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"
> +	 "|[-+*\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\|\\||->|=>|\\.{2}=|\\.{3}|::"),
>  PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
>  	 "[={}\"]|[^={}\" \t]+"),
>  PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
> 
> base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6
-- Hannes
Previous: marcandre.lureau@redhat.comNext: Marc-André Lureau
Message 2 of 9 in “userdiff: add built-in pattern for rust”
  1. userdiff: add built-in pattern for rustmarcandre.lureau@redhat.com, May 20, 2019
  2. Johannes SixtMay 20, 2019
  3. Marc-André LureauMay 21, 2019
  4. Junio C HamanoMay 28, 2019
  5. Johannes SixtMay 28, 2019
  6. Marc-André LureauMay 28, 2019
  7. userdiff: two simplifications of patterns for rustJohannes Sixt, May 30, 2019
  8. Ævar Arnfjörð BjarmasonMay 30, 2019
  9. Johannes SixtMay 30, 2019

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.