Closed dabrahams closed 4 years ago
Short answer: it could be improved. I will try it.
Discussion:
<
and >
are used as either binary operators or angle brackets. Treating them as a bracket unconditionally would break indentation of expressions. So we must distinguish them.
There are two cases where < ... >
is used other than binary operator:
generic-parameter-clause
typealias-declaration
function-declaration
union-style-enum
raw-value-style-enum
struct-declaration
class-declaration
protocol-method-declaration
protocol-initializer-declaration
initializer-declaration
subscript-head
generic-argument-clause
type-identifier
primary-expression
explicit-member-expression
generic-argument-clause
is ambiguous: foo(A < B, C > (d))
could be parsed as foo((A < B), (C > (d)))
or foo(A<B, C>(d))
(invocation of A
with two type arguments B
, C
and one value d
). On the other hand, generic-parameter-clause
seems to be much simpler; looking back one or two tokens is sufficient to recognize the open bracket.
Summary of grammers of generic-parameter-clause
:
typealias-declaration:
"typealias" identifier "<"
function-declaration:
"func" identifier "<"
"func" operator "<"
union-style-enum:
"enum" identifier "<"
raw-value-style-enum
"enum" identifier "<"
struct-declaration
"struct" identifier "<"
class-declaration
"class" identifier "<"
protocol-method-declaration:
"func" identifier "<"
"func" operator "<"
protocol-initializer-declaration
"init" "<"
"init" "?" "<"
"init" "!" "<"
initializer-declaration:
"init" "<"
"init" "?" "<"
"init" "!" "<"
subscript-head:
"subscript" "<"
Fixed by https://github.com/swift-emacs/swift-mode/commit/29759f529032fff9b88a77318a10b2a1ec8ef5c7. Thank you for reporting.
Thank you!
On Fri, Apr 17, 2020 at 11:19 PM taku0 notifications@github.com wrote:
Fixed by 29759f5 https://github.com/swift-emacs/swift-mode/commit/29759f529032fff9b88a77318a10b2a1ec8ef5c7 .
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/swift-emacs/swift-mode/issues/164#issuecomment-615582464, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAKYINTKITSBWAVRZOOMS3RNFA6XANCNFSM4MJ5Q7RQ .
-- Dave
The automatic indentation for cases like this is somewhat suboptimal:
I get:
The original indentation is what I'd have wanted. Generic parameter lists should probably be treated as "parenthesized expressions".