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 as a ~ (b ~ c).

    For example, the Swift subtraction operator (-) is left-associative, such that 5 - 7 - 2 evaluates to -4 ((5 - 7) - 2) rather than 0 (5 - (7 - 2)).

    See more

    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 as a ⧓ (b ⧗ c).

    For example, Swift mathematical operators have the same inherent precedence as their corresponding arithmetic operations, such that 1 + 2 * 3 evaluates to 7 (1 + (2 * 3)) rather than 9 ((1 + 2) * 3).

    See more

    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 is true, the expression entry?.count += 1 has the effect of entry?(.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]

ExpressibleBySyntax

  • Creates an instance initialized with the given syntax node.

    Declaration

    Swift

    public init(_ node: PrecedenceGroupDeclSyntax)