Skip to content

Commit 448d584

Browse files
committed
Add prefix/postfix operators to the built-in operator tables
1 parent 6ba87a8 commit 448d584

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Sources/SwiftOperators/Operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct Operator {
3939

4040
public init(
4141
kind: OperatorKind, name: OperatorName,
42-
precedenceGroup: PrecedenceGroupName?,
42+
precedenceGroup: PrecedenceGroupName? = nil,
4343
syntax: OperatorDeclSyntax? = nil
4444
) {
4545
self.kind = kind

Sources/SwiftOperators/OperatorTable+Defaults.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extension OperatorTable {
2626
]
2727

2828
let operators: [Operator] = [
29+
Operator(kind: .prefix, name: "!"),
2930
Operator(kind: .infix, name: "&&",
3031
precedenceGroup: "LogicalConjunctionPrecedence"),
3132
Operator(kind: .infix, name: "||",
@@ -121,6 +122,21 @@ extension OperatorTable {
121122
]
122123

123124
let operators: [Operator] = [
125+
// Standard postfix operators.
126+
Operator(kind: .postfix, name: "++"),
127+
Operator(kind: .postfix, name: "--"),
128+
Operator(kind: .postfix, name: "..."),
129+
130+
// Standard prefix operators.
131+
Operator(kind: .prefix, name: "++"),
132+
Operator(kind: .prefix, name: "--"),
133+
Operator(kind: .prefix, name: "!"),
134+
Operator(kind: .prefix, name: "~"),
135+
Operator(kind: .prefix, name: "+"),
136+
Operator(kind: .prefix, name: "-"),
137+
Operator(kind: .prefix, name: "..."),
138+
Operator(kind: .prefix, name: "..<"),
139+
124140
// "Exponentiative"
125141
Operator(
126142
kind: .infix,

Tests/SwiftOperatorsTest/SyntaxSynthesisTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class SyntaxSynthesisTests: XCTestCase {
5252
precedencegroup LogicalDisjunctionPrecedence {
5353
associativity: left
5454
}
55+
prefix operator !
5556
infix operator &&: LogicalConjunctionPrecedence
5657
infix operator ||: LogicalDisjunctionPrecedence
5758

0 commit comments

Comments
 (0)