From c8a463000d89c62b213001b0da53e85395db8bbb Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Sun, 24 Mar 2024 12:43:15 +0000 Subject: [PATCH] Handle edge case for startOfScope helper --- Sources/ParsingHelpers.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/ParsingHelpers.swift b/Sources/ParsingHelpers.swift index f339244c..ff96ce29 100644 --- a/Sources/ParsingHelpers.swift +++ b/Sources/ParsingHelpers.swift @@ -141,7 +141,14 @@ public extension Formatter { /// Returns the index of the starting token for the current scope func startOfScope(at index: Int) -> Int? { - self.index(of: .startOfScope, before: index) + self.index(of: .startOfScope, before: index).flatMap { + if [.startOfScope("//"), .startOfScope("#!")].contains(tokens[$0]), + self.index(of: .linebreak, after: $0) ?? index < index + { + return nil + } + return $0 + } } /// Returns the index of the ending token for the current scope