#4100·prism

Swift class regex doesn't support private names (ex. '_Foo')

Author: Kenna-BlackburnCreated Aug 21, 2026Updated Aug 21, 2026

https://github.com/PrismJS/prism/blob/d805f30275e279907cbad8a339a3d899fc0ea8d8/src/languages/swift.js#L139-L140

In swift, we have a pattern of naming private things a client can but really shouldn't touch with one or more prefixed underscore. With the current regex though, it must start with /[A-Z]/, is something like _Foo would not match. The solution could be as simple as: /\b_*[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/, or /\b(?:_+)?[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/.

Technically swift also supports naming both classes (and funcs and vars) literally anything (even including whitespace) by wrapping the name in backticks (ex. `Foo Bar`), but that's very rarely used and I think can safely be excluded.