Skip to content

Commit c771a8d

Browse files
committed
fix detection of modifier keywords
1 parent 9676fa5 commit c771a8d

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

Sources/MarkdownPluginSwift/Signature.Expanded (ext).swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ extension Signature.Expanded
3838
@inlinable @_spi(testable) public
3939
init(_ string:String)
4040
{
41-
var keywords:InterestingKeywords = .init()
41+
var ignored:InterestingKeywords = .init()
42+
self.init(string, keywords: &ignored)
43+
}
44+
45+
@inlinable @_spi(testable) public
46+
init(_ string:String, keywords:inout InterestingKeywords)
47+
{
4248
var empty:[Int: Scalar] = [:]
4349
self.init(utf8: [UInt8].init(string.utf8), keywords: &keywords, symbols: &empty)
4450
}

Sources/MarkdownPluginSwift/SignatureSyntax.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ extension SignatureSyntax
3131
{
3232
if let region:TokenSyntax = region.as(TokenSyntax.self)
3333
{
34+
// Allows us to detect phylum keywords.
35+
self.append(region: region, at: .toplevel)
36+
}
37+
else if
38+
let region:ModifierListSyntax = region.as(ModifierListSyntax.self)
39+
{
40+
// Allows us to detect `class` modifier keywords.
3441
self.append(region: region, at: .toplevel)
3542
}
3643
else if

Sources/MarkdownPluginSwiftTests/Main.swift

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ enum Main:SyncTests
1414
{
1515
if let tests:TestGroup = tests / "Signatures"
1616
{
17-
1817
if let tests:TestGroup = tests / "Expanded"
1918
{
2019
let decl:String = """
@@ -125,5 +124,53 @@ enum Main:SyncTests
125124
""")
126125
}
127126
}
127+
128+
if let tests:TestGroup = tests / "InterestingKeywords"
129+
{
130+
if let tests:TestGroup = tests / "Actor"
131+
{
132+
let decl:String = "actor MargotRobbie"
133+
134+
var keywords:Signature<Never>.Expanded.InterestingKeywords = .init()
135+
let expanded:Signature<Never>.Expanded = .init(decl,
136+
keywords: &keywords)
137+
138+
tests.expect("\(expanded.bytecode.safe)" ==? decl)
139+
tests.expect(true: keywords.actor)
140+
}
141+
if let tests:TestGroup = tests / "ClassSubscript"
142+
{
143+
let decl:String = "class subscript(index: Int) -> Int"
144+
145+
var keywords:Signature<Never>.Expanded.InterestingKeywords = .init()
146+
let expanded:Signature<Never>.Expanded = .init(decl,
147+
keywords: &keywords)
148+
149+
tests.expect("\(expanded.bytecode.safe)" ==? decl)
150+
tests.expect(true: keywords.class)
151+
}
152+
if let tests:TestGroup = tests / "ClassFunc"
153+
{
154+
let decl:String = "class func x() -> Int"
155+
156+
var keywords:Signature<Never>.Expanded.InterestingKeywords = .init()
157+
let expanded:Signature<Never>.Expanded = .init(decl,
158+
keywords: &keywords)
159+
160+
tests.expect("\(expanded.bytecode.safe)" ==? decl)
161+
tests.expect(true: keywords.class)
162+
}
163+
if let tests:TestGroup = tests / "ClassVar"
164+
{
165+
let decl:String = "class var x: Int { get }"
166+
167+
var keywords:Signature<Never>.Expanded.InterestingKeywords = .init()
168+
let expanded:Signature<Never>.Expanded = .init(decl,
169+
keywords: &keywords)
170+
171+
tests.expect("\(expanded.bytecode.safe)" ==? decl)
172+
tests.expect(true: keywords.class)
173+
}
174+
}
128175
}
129176
}

0 commit comments

Comments
 (0)