Skip to content

Commit

Permalink
Allow declarations that start with a multiline comment
Browse files Browse the repository at this point in the history
The semi-suppressor is a little too aggressive: if it sees something
like:

```
class Foo {
    let property1: String

    /* visible for testing */ var property2: String
}
```

It will suppress the newlines before `property2` and cause compilation
to fail. If the comment were on its own line, it would be fine, because
there's still another semi in the way.

The best way to fix this seems to be to allow multiline comments
themselves to count as separators.
  • Loading branch information
alex-pinkus committed Dec 31, 2021
1 parent fb5da3e commit efc9d5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion corpus/classes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Class with methods and expressions
==================

class Strings {
/// Some awesome docummentation!
/// Yay
func aString() -> String { return "Hello World!" }

func anotherString() -> String { return "Hello" + " " + "World" }
Expand All @@ -55,6 +57,8 @@ class Strings {
(source_file
(class_declaration (type_identifier)
(class_body
(comment)
(comment)
(function_declaration
(simple_identifier)
(user_type (type_identifier))
Expand All @@ -77,7 +81,7 @@ Class with modifiers
internal open class Test {
private(set) var isRunning: Bool
internal(set) var isFailed: Bool
private final func test() { }
/* some comment */ private final func test() { }
}

---
Expand All @@ -95,6 +99,7 @@ internal open class Test {
(modifiers (visibility_modifier))
(value_binding_pattern (non_binding_pattern (simple_identifier)))
(type_annotation (user_type (type_identifier))))
(multiline_comment)
(function_declaration
(modifiers (visibility_modifier) (inheritance_modifier))
(simple_identifier)
Expand Down
6 changes: 5 additions & 1 deletion grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,12 @@ module.exports = grammar({
$._type
),

_class_member_separator: ($) => choice($._semi, $.multiline_comment),
_class_member_declarations: ($) =>
seq(sep1($._type_level_declaration, $._semi), optional($._semi)),
seq(
sep1($._type_level_declaration, $._class_member_separator),
optional($._class_member_separator)
),

_function_value_parameters: ($) =>
seq("(", optional(sep1($._function_value_parameter, ",")), ")"),
Expand Down
1 change: 0 additions & 1 deletion script-data/known_failures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ RxSwift/RxExample/RxExample/Examples/GitHubSearchRepositories/GitHubSearchReposi
RxSwift/Rx.playground/Pages/Transforming_Operators.xcplaygroundpage/Contents.swift
SwiftLint/Source/SwiftLintFramework/Extensions/String+SwiftLint.swift
GRDB/GRDB/Core/Row.swift
GRDB/GRDB/Core/Statement.swift

0 comments on commit efc9d5e

Please sign in to comment.