Skip to content

Commit

Permalink
Fix indentation of repeat each
Browse files Browse the repository at this point in the history
  • Loading branch information
taku0 committed Jun 22, 2024
1 parent 12f25fc commit b06c97b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
8 changes: 7 additions & 1 deletion swift-mode-lexer.el
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ return non-nil."
"isolated" "each"))
(member (swift-mode:token:text next-token)
'("any" "some" "inout" "borrowing" "consuming" "throws"
"rethrows" "in" "where" "isolated")))
"rethrows" "in" "where" "isolated" "each")))
nil)

;; Before async
Expand Down Expand Up @@ -731,6 +731,12 @@ return non-nil."
"let" "var" "throw" "import"))
nil)

;; Suppress import semicolon after `repeat' unless followed by a open
;; curly bracket.
((and (equal (swift-mode:token:text previous-token) "repeat")
(not (eq (swift-mode:token:type next-token) '{)))
nil)

;; Inserts implicit semicolon before keywords that starts a new
;; statement.
((member (swift-mode:token:text next-token)
Expand Down
10 changes: 5 additions & 5 deletions test/swift-files/indent/declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -863,20 +863,20 @@ func foo()


// Value and Type Parameter Packs
// https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md#introduction
// https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
// https://github.com/apple/swift-evolution/blob/main/proposals/0398-variadic-types.md

func constrain<each S: Sequence>(
_: repeat
each // swift-mode:test:known-bug
S // swift-mode:test:known-bug
each
S
) where (
repeat
( // swift-mode:test:known-bug
(
each
S
)
.Element
.Element
) == (Int, String) {
}

Expand Down
20 changes: 20 additions & 0 deletions test/swift-files/indent/statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ for
foo()
}

// Pack iteration
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0408-pack-iteration.md
for element
in
repeat
each
element {
}

for (left, right)
in
repeat
(
each
lhs,
each
rhs
) {
}


// While statements

Expand Down

0 comments on commit b06c97b

Please sign in to comment.