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

Re: [PATCH v2] userdiff: better method/property matching for C#

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2024, 02:11 UTC
Message-ID
<xmqqv85yokoc.fsf@gitster.g>
In-Reply-To
<pull.1682.v2.git.git.1709756493673.gitgitgadget@gmail.com>
"Steven Jeuris via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 12 quoted lines
> From: Steven Jeuris <steven.jeuris@3shape.com>
>
> - Support multi-line methods by not requiring closing parenthesis.
> - Support multiple generics (comma was missing before).
> - Add missing `foreach`, `lock` and  `fixed` keywords to skip over.
> - Remove `instanceof` keyword, which isn't C#.
> - Also detect non-method keywords not positioned at the start of a line.
> - Added tests; none existed before.
>
> The overall strategy is to focus more on what isn't expected for
> method/property definitions, instead of what is, but is fully optional.
>

Roughly in other words, we assume that any file the end user throws at us is a well formed program, so instead of enumerating all valid keywords and limit the match exactly to them, use a pattern that would match valid keywords (both currently known ones, and anything the language might add in the future that we do not know about), to match with anything syntactically plausible to be a definition?

It does make sense to start by assuming that the end user data is a valid C# program.

> Signed-off-by: Steven Jeuris <steven.jeuris@gmail.com>
> ---
Show 16 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index e399543823b..5a9e8a0ef55 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -89,12 +89,18 @@ PATTERNS("cpp",
>  	 "|\\.[0-9][0-9]*([Ee][-+]?[0-9]+)?[fFlL]?"
>  	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*|<=>"),
>  PATTERNS("csharp",
> -	 /* Keywords */
> -	 "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
> -	 /* Methods and constructors */
> -	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe|async)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
> +	 /*
> +	  * Jump over keywords not used by methods which can be followed by parentheses without special characters in between,
> +	  * making them look like methods.
> +	  */
Overly long comments (I'll wrap them while queuing).
Show 14 quoted lines
> +	 "!(^|[ \t]+)(do|while|for|foreach|if|else|new|default|return|switch|case|throw|catch|using|lock|fixed)([ \t(]+|$)\n"
> +	 /* Methods/constructors:
> +	  * the strategy is to identify a minimum of two groups (any combination of keywords/type/name),
> +	  * without intermediate or final characters which can't be part of method definitions before the opening parenthesis.
> +	  */
> +	 "^[ \t]*(([][[:alnum:]@_<>.,]*[^=:{ \t][ \t]+[][[:alnum:]@_<>.,]*)+\\([^;]*)$\n"
>  	 /* Properties */
> -	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
> +	 "^[ \t]*((([][[:alnum:]@_<>.,]+)[ \t]+[][[:alnum:]@_]*)+[^=:;,()]*)$\n"
>  	 /* Type definitions */
>  	 "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct|record)[ \t]+.*)$\n"
>  	 /* Namespace */
>
> base-commit: f41f85c9ec8d4d46de0fd5fded88db94d3ec8c11
Previous: Steven Jeuris via GitGitGadgetNext: Linus Arver
Message 3 of 14 in “userdiff: better method/property matching for C#”
  1. userdiff: better method/property matching for C#Steven Jeuris via GitGitGadget, Feb 25, 2024
  2. userdiff: better method/property matching for C#Steven Jeuris via GitGitGadget, Mar 6, 2024
  3. Junio C HamanoMar 7, 2024
  4. Linus ArverMar 16, 2024
  5. Junio C HamanoMar 26, 2024
  6. Jeff KingMar 27, 2024
  7. Johannes SixtMar 27, 2024
  8. userdiff: better method/property matching for C#Steven Jeuris via GitGitGadget, Mar 28, 2024
  9. userdiff: better method/property matching for C#Steven Jeuris via GitGitGadget, Mar 28, 2024
  10. Junio C HamanoMar 28, 2024
  11. Johannes SixtMar 30, 2024
  12. userdiff: better method/property matching for C#Steven Jeuris via GitGitGadget, Apr 3, 2024
  13. Johannes SixtApr 5, 2024
  14. Junio C HamanoApr 5, 2024

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.