Skip to content

Commit 8dbec02

Browse files
committed
fixing more force tries
1 parent eec3033 commit 8dbec02

24 files changed

Lines changed: 108 additions & 76 deletions

File tree

Examples/Completed/conditionals/dsl.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Group {
2323
Call("print", "Good job!")
2424
}
2525
If {
26-
try! Infix("score", ">=", 70)
26+
try Infix("score", ">=", 70)
2727
} then: {
2828
Call("print", "Passing")
2929
}
@@ -172,24 +172,24 @@ Infix("board[24]", "-=", 8)
172172
Variable(.var, name: "square", equals: 0)
173173
Variable(.var, name: "diceRoll", equals: 0)
174174
While {
175-
try! Infix("square", "!=", "finalSquare")
175+
try Infix("square", "!=", "finalSquare")
176176
} then: {
177177
Assignment("diceRoll", "+", 1)
178178
If {
179-
try! Infix("diceRoll", "==", 7)
179+
try Infix("diceRoll", "==", 7)
180180
} then: {
181181
Assignment("diceRoll", 1)
182182
}
183-
Switch(try! Infix("square", "+", "diceRoll")) {
183+
Switch(try Infix("square", "+", "diceRoll")) {
184184
SwitchCase("finalSquare") {
185185
Break()
186186
}
187-
SwitchCase(try! Infix("newSquare", ">", "finalSquare")) {
187+
SwitchCase(try Infix("newSquare", ">", "finalSquare")) {
188188
Continue()
189189
}
190190
Default {
191-
try! Infix("square", "+=", "diceRoll")
192-
try! Infix("square", "+=", "board[square]")
191+
try Infix("square", "+=", "diceRoll")
192+
try Infix("square", "+=", "board[square]")
193193
}
194194
}
195195
}
@@ -216,7 +216,7 @@ For {
216216
} in: {
217217
Literal.array([Literal.integer(1), Literal.integer(2), Literal.integer(3), Literal.integer(4), Literal.integer(5), Literal.integer(6), Literal.integer(7), Literal.integer(8), Literal.integer(9), Literal.integer(10)])
218218
} where: {
219-
try! Infix("number", "%", 2)
219+
try Infix("number", "%", 2)
220220
} then: {
221221
Call("print", "Even number: \\(number)")
222222
}

Examples/Completed/for_loops/dsl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Group {
4040
Variable(.let, name: "numbers", equals: Literal.array([Literal.integer(1), Literal.integer(2), Literal.integer(3), Literal.integer(4), Literal.integer(5), Literal.integer(6), Literal.integer(7), Literal.integer(8), Literal.integer(9), Literal.integer(10)]))
4141

4242
For(VariableExp("number"), in: VariableExp("numbers"), where: {
43-
try! Infix("==") {
44-
try! Infix("%") {
43+
try Infix("==") {
44+
try Infix("%") {
4545
VariableExp("number")
4646
Literal.integer(2)
4747
}
@@ -68,4 +68,4 @@ Group {
6868
ParameterExp(unlabeled: "\"\\(name): \\(score)\"")
6969
}
7070
})
71-
}
71+
}

Macros/SKSampleMacro/Sources/SKSampleMacroMacros/SKSampleMacroMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct StringifyMacro: ExpressionMacro {
2525
}
2626

2727
return Tuple{
28-
try! Infix("+") {
28+
try Infix("+") {
2929
VariableExp(first.description)
3030
VariableExp(second.description)
3131
}

Sources/SyntaxKit/ControlFlow/For.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// Permission is hereby granted, free of charge, to any person
99
// obtaining a copy of this software and associated documentation
10-
// files (the "Software"), to deal in the Software without
10+
// files (the Software), to deal in the Software without
1111
// restriction, including without limitation the rights to use,
1212
// copy, modify, merge, publish, distribute, sublicense, and/or
1313
// sell copies of the Software, and to permit persons to whom the
@@ -17,7 +17,7 @@
1717
// The above copyright notice and this permission notice shall be
1818
// included in all copies or substantial portions of the Software.
1919
//
20-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
2121
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
2222
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2323
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT

Sources/SyntaxKit/ControlFlow/Switch.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public struct Switch: CodeBlock {
3838
/// - Parameters:
3939
/// - expression: The expression to switch on.
4040
/// - content: A ``CodeBlockBuilder`` that provides the cases for the switch.
41-
public init(_ expression: CodeBlock, @CodeBlockBuilderResult _ content: () throws -> [CodeBlock]) rethrows {
41+
public init(_ expression: CodeBlock, @CodeBlockBuilderResult _ content: () throws -> [CodeBlock])
42+
rethrows
43+
{
4244
self.expression = expression
4345
self.cases = try content()
4446
}
@@ -47,7 +49,9 @@ public struct Switch: CodeBlock {
4749
/// - Parameters:
4850
/// - expression: The string expression to switch on.
4951
/// - content: A ``CodeBlockBuilder`` that provides the cases for the switch.
50-
public init(_ expression: String, @CodeBlockBuilderResult _ content: () throws -> [CodeBlock]) rethrows {
52+
public init(_ expression: String, @CodeBlockBuilderResult _ content: () throws -> [CodeBlock])
53+
rethrows
54+
{
5155
self.expression = VariableExp(expression)
5256
self.cases = try content()
5357
}

Sources/SyntaxKit/ControlFlow/SwitchCase.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public struct SwitchCase: CodeBlock {
3939
/// - patterns: The patterns to match for the case. Can be `PatternConvertible`,
4040
/// `CodeBlock`, or `SwitchLet` for value binding.
4141
/// - content: A ``CodeBlockBuilder`` that provides the body of the case.
42-
public init(_ patterns: Any..., @CodeBlockBuilderResult content: () throws -> [CodeBlock]) rethrows {
42+
public init(_ patterns: Any..., @CodeBlockBuilderResult content: () throws -> [CodeBlock])
43+
rethrows
44+
{
4345
self.patterns = patterns
4446
self.body = try content()
4547
}
@@ -48,7 +50,10 @@ public struct SwitchCase: CodeBlock {
4850
/// - Parameters:
4951
/// - conditional: A ``CodeBlockBuilder`` that provides the conditional patterns for the case.
5052
/// - content: A ``CodeBlockBuilder`` that provides the body of the case.
51-
public init(@CodeBlockBuilderResult conditional: () throws -> [CodeBlock], @CodeBlockBuilderResult content: () throws -> [CodeBlock]) rethrows {
53+
public init(
54+
@CodeBlockBuilderResult conditional: () throws -> [CodeBlock],
55+
@CodeBlockBuilderResult content: () throws -> [CodeBlock]
56+
) rethrows {
5257
self.patterns = try conditional()
5358
self.body = try content()
5459
}

Sources/SyntaxKit/ControlFlow/While.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public struct While: CodeBlock {
4141
/// - then: A ``CodeBlockBuilder`` that provides the body of the loop.
4242
public init(
4343
_ condition: any ExprCodeBlock,
44-
@CodeBlockBuilderResult then: () -> [CodeBlock]
45-
) {
44+
@CodeBlockBuilderResult then: () throws -> [CodeBlock]
45+
) rethrows {
4646
self.condition = condition
47-
self.body = then()
47+
self.body = try then()
4848
self.isRepeatWhile = false
4949
}
5050

@@ -53,11 +53,11 @@ public struct While: CodeBlock {
5353
/// - condition: A `CodeBlockBuilder` that produces exactly one condition expression.
5454
/// - then: A ``CodeBlockBuilder`` that provides the body of the loop.
5555
public init(
56-
@ExprCodeBlockBuilder _ condition: () -> any ExprCodeBlock,
57-
@CodeBlockBuilderResult then: () -> [CodeBlock]
58-
) {
59-
self.condition = condition()
60-
self.body = then()
56+
@ExprCodeBlockBuilder _ condition: () throws -> any ExprCodeBlock,
57+
@CodeBlockBuilderResult then: () throws -> [CodeBlock]
58+
) rethrows {
59+
self.condition = try condition()
60+
self.body = try then()
6161
self.isRepeatWhile = false
6262
}
6363

Sources/SyntaxKit/Core/ExprCodeBlockBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// Permission is hereby granted, free of charge, to any person
99
// obtaining a copy of this software and associated documentation
10-
// files (the "Software"), to deal in the Software without
10+
// files (the Software), to deal in the Software without
1111
// restriction, including without limitation the rights to use,
1212
// copy, modify, merge, publish, distribute, sublicense, and/or
1313
// sell copies of the Software, and to permit persons to whom the
@@ -17,10 +17,10 @@
1717
// The above copyright notice and this permission notice shall be
1818
// included in all copies or substantial portions of the Software.
1919
//
20-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
2121
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
2222
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHERS OR COPYRIGHT
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
2424
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2525
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2626
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

Sources/SyntaxKit/Core/PatternConvertibleBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// Permission is hereby granted, free of charge, to any person
99
// obtaining a copy of this software and associated documentation
10-
// files (the "Software"), to deal in the Software without
10+
// files (the Software), to deal in the Software without
1111
// restriction, including without limitation the rights to use,
1212
// copy, modify, merge, publish, distribute, sublicense, and/or
1313
// sell copies of the Software, and to permit persons to whom the
@@ -17,10 +17,10 @@
1717
// The above copyright notice and this permission notice shall be
1818
// included in all copies or substantial portions of the Software.
1919
//
20-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
2121
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
2222
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHERS OR COPYRIGHT
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
2424
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2525
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2626
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

Sources/SyntaxKit/Declarations/Class.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public struct Class: CodeBlock {
4242
/// - Parameters:
4343
/// - name: The name of the class.
4444
/// - content: A ``CodeBlockBuilder`` that provides the body of the class.
45-
public init(_ name: String, @CodeBlockBuilderResult _ content: () throws -> [CodeBlock]) rethrows {
45+
public init(_ name: String, @CodeBlockBuilderResult _ content: () throws -> [CodeBlock]) rethrows
46+
{
4647
self.name = name
4748
self.members = try content()
4849
}

0 commit comments

Comments
 (0)