Thread (11 messages) 11 messages, 4 authors, 6h ago

Re: [PATCH v2] userdiff: add support for Swift

From: Junio C Hamano <hidden>
Date: 2026-07-21 19:33:31

Shlok Kulshreshtha [off-list ref] writes:
Add a built-in userdiff driver for the Swift programming language so that
diff hunk headers and word diffs work out of the box for ".swift" files.

The funcname pattern is built for Swift's own declaration grammar: an
optional run of attributes ("@objc", "@available(iOS 13, *)", ...),
followed by an optional run of lowercase modifiers ("public", "static",
"final", ...), followed by a declaration keyword (func, class, struct,
enum, protocol, extension, actor, init, deinit, subscript). The keyword
is followed by a boundary that allows whitespace, "(" (init/subscript),
"?" or "!" (failable init), or "<" (generics), while still acting as a
word boundary so e.g. "initialize(" does not match.

The word regex recognizes Swift identifiers, hexadecimal, octal, binary,
integer and floating-point literals, and the language's operators.

Signed-off-by: Shlok Kulshreshtha <redacted>
---
v2, addressing Johannes Sixt's review of v1
([ref]).  Changes since v1:

 - t4018/swift-{init,failable-init,generic-subscript}: "RIGHT" now
   appears only once, on the declaration line, so the expected header is
   unambiguous.
 - word regex: dropped the redundant "?" after the single-character
   operator class.  Single characters are already covered by the
   "|[^[:space:]]" fallback that the PATTERNS macro appends, so only the
   two-character forms need to be spelled out.

(A couple of Hannes's other suggestions I kept as-is; I have explained
the reasoning in a reply to his review.)
Thanks for an update.

Let's wait for a few days to see if we hear more comments and
otherwise mark the topic for 'next'.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help