Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swift) ensure keyword attributes highlight correctly #3955

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
End keyword attributes on whitespace or opening paren
bradleymackey committed Jan 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 75c41f052e4452e3e848a2f785fbd788f0a0c538
5 changes: 4 additions & 1 deletion src/languages/swift.js
Original file line number Diff line number Diff line change
@@ -257,14 +257,17 @@ export default function(hljs) {
}
] }
};

const KEYWORD_ATTRIBUTE = {
scope: 'keyword',
match: concat(/@/, either(...Swift.keywordAttributes))
match: concat(/@/, either(...Swift.keywordAttributes), lookahead(either(/\(/, /\s+/))),
};

const USER_DEFINED_ATTRIBUTE = {
scope: 'meta',
match: concat(/@/, Swift.identifier)
};

const ATTRIBUTES = [
AVAILABLE_ATTRIBUTE,
KEYWORD_ATTRIBUTE,
7 changes: 6 additions & 1 deletion test/markup/swift/attributes.expect.txt
Original file line number Diff line number Diff line change
@@ -5,8 +5,13 @@
<span class="hljs-keyword">@propertyWrapper</span>
<span class="hljs-meta">@SomeWrapper</span>(value: <span class="hljs-number">1.0</span>, other: <span class="hljs-string">&quot;string&quot;</span>, bool: <span class="hljs-literal">false</span>)
<span class="hljs-keyword">@resultBuilder</span>
<span class="hljs-keyword">@Sendable</span>
<span class="hljs-keyword">@unchecked</span>
<span class="hljs-keyword">@warn_unqualified_access</span>

<span class="hljs-keyword">@objc</span>
<span class="hljs-keyword">@objcMembers</span>
<span class="hljs-meta">@CustomAttribute</span>
<span class="hljs-keyword">@Sendable</span>
<span class="hljs-meta">@SendableCustom</span>

@ notAnAttribute
7 changes: 6 additions & 1 deletion test/markup/swift/attributes.txt
Original file line number Diff line number Diff line change
@@ -5,8 +5,13 @@
@propertyWrapper
@SomeWrapper(value: 1.0, other: "string", bool: false)
@resultBuilder
@Sendable
@unchecked
@warn_unqualified_access

@objc
@objcMembers
@CustomAttribute
@Sendable
@SendableCustom

@ notAnAttribute
3 changes: 3 additions & 0 deletions test/markup/swift/macro.expect.txt
Original file line number Diff line number Diff line change
@@ -6,4 +6,7 @@
<span class="hljs-keyword">@attached</span>(member)
<span class="hljs-keyword">macro</span> <span class="hljs-title function_">OptionSetMembers</span>()

<span class="hljs-keyword">@attached</span>(peer, names: overloaded)
<span class="hljs-keyword">macro</span> <span class="hljs-title function_">OptionSetMembers</span>()

#myMacro()
3 changes: 3 additions & 0 deletions test/markup/swift/macro.txt
Original file line number Diff line number Diff line change
@@ -6,4 +6,7 @@ macro error(_ message: String) = #externalMacro(module: "MyMacros", type: "Error
@attached(member)
macro OptionSetMembers()

@attached(peer, names: overloaded)
macro OptionSetMembers()

#myMacro()