PrecedenceGroup
public struct PrecedenceGroup : Declaration, Hashable, Codable
extension PrecedenceGroup: ExpressibleBySyntax
An operator precedence group declaration.
-
The associativity of an operator, which determines how operators of the same precedence are grouped in the absence of parentheses.
Consider the expression
a ~ b ~ c
: If the~
operator is left-associative, then the expression is interpreted as(a ~ b) ~ c
. If the~
operator is right-associative, then the expression is interpreted asa ~ (b ~ c)
.For example, the Swift subtraction operator (
See more-
) is left-associative, such that5 - 7 - 2
evaluates to-4
((5 - 7) - 2
) rather than0
(5 - (7 - 2)
).Declaration
Swift
public enum Associativity : String, Hashable, Codable
-
The relation of operators to operators in other precedence groups, which determines the order in which operators of different precedence groups are evaluated in absence of parentheses.
Consider the expression
a ⧓ b ⧗ c
. If the⧓
operator has a higher precedence than⧗
, then the expression is interpreted as(a ⧓ b) ⧗ c
. If the⧓
operator has a lower precedence than⧗
, then the expression is interpreted asa ⧓ (b ⧗ c)
.For example, Swift mathematical operators have the same inherent precedence as their corresponding arithmetic operations, such that
See more1 + 2 * 3
evaluates to7
(1 + (2 * 3)
) rather than9
((1 + 2) * 3
).Declaration
Swift
public enum Relation : Hashable
extension PrecedenceGroup.Relation: Comparable
extension PrecedenceGroup.Relation: Codable
-
The declaration attributes.
Declaration
Swift
public let attributes: [Attribute]
-
The declaration modifiers.
Declaration
Swift
public let modifiers: [Modifier]
-
The declaration keyword (
"precedencegroup"
)Declaration
Swift
public let keyword: String
-
The precedence group name.
Declaration
Swift
public let name: String
-
Whether operators in the precedence group are folded into optional chains.
For example, if
assignment
istrue
, the expressionentry?.count += 1
has the effect ofentry?(.count += 1)
; otherwise, the same expression is interpreted as(entry?.count) += 1
and fails to type-check.Declaration
Swift
public let assignment: Bool?
-
The associativity of operators in the precedence group.
Declaration
Swift
public let associativity: Associativity?
-
The relation of operators to operators in other precedence groups.
Declaration
Swift
public let relations: [Relation]
-
Creates an instance initialized with the given syntax node.
Declaration
Swift
public init(_ node: PrecedenceGroupDeclSyntax)