enh(swift) macro attributes are highlighted as keywords (#3844)

* Fixup attributes

- Add macro attributes

* Update tests for the attributes

* Update changes
This commit is contained in:
Bradley Mackey 2023-08-18 02:00:41 +01:00 committed by GitHub
parent 12536569dc
commit 7db19e7e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 3 deletions

View File

@ -36,6 +36,7 @@ Core Grammars:
- enh(rust) added `eprintln!` macro [qoheniac][]
- enh(leaf) update syntax to 4.0 [Samuel Bishop][]
- fix(swift) `warn_unqualified_access` is an attribute [Bradley Mackey][]
- enh(swift) macro attributes are highlighted as keywords [Bradley Mackey][]
Dev tool:

View File

@ -282,13 +282,16 @@ export const typeIdentifier = concat(/[A-Z]/, identifierCharacter, '*');
// Built-in attributes, which are highlighted as keywords.
// @available is handled separately.
// https://docs.swift.org/swift-book/documentation/the-swift-programming-language/attributes
export const keywordAttributes = [
'attached',
'autoclosure',
concat(/convention\(/, either('swift', 'block', 'c'), /\)/),
'discardableResult',
'dynamicCallable',
'dynamicMemberLookup',
'escaping',
'freestanding',
'frozen',
'GKInspectable',
'IBAction',

View File

@ -1,6 +1,9 @@
<span class="hljs-keyword">macro</span> <span class="hljs-title function_">warning</span>(<span class="hljs-keyword">_</span> <span class="hljs-params">message</span>: <span class="hljs-type">String</span>) <span class="hljs-operator">=</span> #externalMacro(module: <span class="hljs-string">&quot;MyMacros&quot;</span>, type: <span class="hljs-string">&quot;WarningMacro&quot;</span>)
<span class="hljs-meta">@freestanding</span>(declaration)
<span class="hljs-keyword">@freestanding</span>(declaration)
<span class="hljs-keyword">macro</span> <span class="hljs-title function_">error</span>(<span class="hljs-keyword">_</span> <span class="hljs-params">message</span>: <span class="hljs-type">String</span>) <span class="hljs-operator">=</span> #externalMacro(module: <span class="hljs-string">&quot;MyMacros&quot;</span>, type: <span class="hljs-string">&quot;ErrorMacro&quot;</span>)
#myMacro()
<span class="hljs-keyword">@attached</span>(member)
<span class="hljs-keyword">macro</span> <span class="hljs-title function_">OptionSetMembers</span>()
#myMacro()

View File

@ -3,4 +3,7 @@ macro warning(_ message: String) = #externalMacro(module: "MyMacros", type: "War
@freestanding(declaration)
macro error(_ message: String) = #externalMacro(module: "MyMacros", type: "ErrorMacro")
#myMacro()
@attached(member)
macro OptionSetMembers()
#myMacro()