Skip to content

Commit 61fb486

Browse files
authored
Merge pull request #70 from brightdigit/v0.0.2
v0.0.2(#64)
2 parents e28e3e5 + 7338cc0 commit 61fb486

312 files changed

Lines changed: 25295 additions & 1914 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/SyntaxKit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
restore-keys: |
123123
${{ runner.os }}-mint-
124124
- name: Install mint
125-
if: steps.cache-mint.outputs.cache-hit != 'true'
125+
if: steps.cache-mint.outputs.cache-hit == ''
126126
run: |
127127
git clone https://github.com/yonaskolb/Mint.git
128128
cd Mint

.swiftlint.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ opt_in_rules:
1111
- contains_over_range_nil_comparison
1212
- convenience_type
1313
- discouraged_object_literal
14-
- discouraged_optional_boolean
1514
- empty_collection_literal
1615
- empty_count
1716
- empty_string
@@ -41,7 +40,7 @@ opt_in_rules:
4140
- legacy_random
4241
- literal_expression_end_indentation
4342
- lower_acl_than_parent
44-
# - missing_docs
43+
- missing_docs
4544
- modifier_order
4645
- multiline_arguments
4746
- multiline_arguments_brackets
@@ -78,7 +77,7 @@ opt_in_rules:
7877
- strong_iboutlet
7978
- toggle_bool
8079
# - trailing_closure
81-
- type_contents_order
80+
# - type_contents_order
8281
- unavailable_function
8382
- unneeded_parentheses_in_closure_argument
8483
- unowned_variable_capture
@@ -111,11 +110,17 @@ identifier_name:
111110
excluded:
112111
- id
113112
- no
113+
type_name:
114+
excluded:
115+
- If
116+
- Do
114117
excluded:
115118
- DerivedData
116119
- .build
117120
- Mint
118121
- Examples
122+
- Macros
123+
- Sources/SyntaxKit/Parser
119124
indentation_width:
120125
indentation_width: 2
121126
file_name:
@@ -129,3 +134,4 @@ disabled_rules:
129134
- closure_parameter_position
130135
- trailing_comma
131136
- opening_brace
137+
- optional_data_string_conversion
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@objc
2+
class Foo {
3+
@Published var bar: String = "bar"
4+
5+
@available(iOS 17.0, *)
6+
func bar() {
7+
print("bar")
8+
}
9+
10+
@MainActor
11+
func baz() {
12+
print("baz")
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Class("Foo") {
2+
Variable(.var, name: "bar", type: "String", defaultValue: "bar").attribute("Published")
3+
Function("bar") {
4+
print("bar")
5+
}.attribute("available", arguments: ["iOS 17.0", "*"])
6+
Function("baz") {
7+
}.attribute("objc")}.attribute("objc")

Examples/Completed/attributes/syntax.json

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
enum VendingMachineError: Error {
2+
case invalidSelection
3+
case insufficientFunds(coinsNeeded: Int)
4+
case outOfStock
5+
}
6+
7+
class VendingMachine {
8+
var inventory = [
9+
"Candy Bar": Item(price: 12, count: 7),
10+
"Chips": Item(price: 10, count: 4),
11+
"Pretzels": Item(price: 7, count: 11)
12+
]
13+
var coinsDeposited = 0
14+
15+
16+
func vend(itemNamed name: String) throws {
17+
guard let item = inventory[name] else {
18+
throw VendingMachineError.invalidSelection
19+
}
20+
21+
22+
guard item.count > 0 else {
23+
throw VendingMachineError.outOfStock
24+
}
25+
26+
27+
guard item.price <= coinsDeposited else {
28+
throw VendingMachineError.insufficientFunds(coinsNeeded: item.price - coinsDeposited)
29+
}
30+
31+
32+
coinsDeposited -= item.price
33+
34+
35+
var newItem = item
36+
newItem.count -= 1
37+
inventory[name] = newItem
38+
39+
40+
print("Dispensing \(name)")
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Enum("VendingMachineError") {
2+
Case("invalidSelection")
3+
Case("insufficientFunds").associatedValue("coinsNeeded", type: "Int")
4+
Case("outOfStock")
5+
}
6+
7+
Class("VendingMachine") {
8+
Variable(.var, name: "inventory", equals: Literal.dictionary(Dictionary(uniqueKeysWithValues: [
9+
("Candy Bar", Item(price: 12, count: 7)),
10+
("Chips", Item(price: 10, count: 4)),
11+
("Pretzels", Item(price: 7, count: 11))
12+
])))
13+
Variable(.var, name: "coinsDeposited", equals: 0)
14+
15+
Function("vend"){
16+
Parameter("name", labeled: "itemNamed", type: "String")
17+
} _: {
18+
Guard("let item = inventory[itemNamed]") else: {
19+
Throw(
20+
EnumValue("VendingMachineError", case: "invalidSelection")
21+
)
22+
}
23+
Guard("item.count > 0") else: {
24+
Throw(
25+
EnumValue("VendingMachineError", case: "outOfStock")
26+
)
27+
}
28+
Guard("item.price <= coinsDeposited") else: {
29+
Throw(
30+
EnumValue("VendingMachineError", case: "insufficientFunds"){
31+
ParameterExp("coinsNeeded", value: Infix("-"){
32+
VariableExp("item").property("price")
33+
VariableExp("coinsDeposited")
34+
})
35+
}
36+
)
37+
}
38+
Infix("-=", "coinsDeposited", VariableExp("item").property("price"))
39+
Variable("newItem", equals: VariableExp("item"))
40+
Infix("-=", "newItem.count", 1)
41+
Assignment("inventory[itemNamed]", .ref("newItem"))
42+
Call("print", "Dispensing \\(itemNamed)")
43+
}
44+
}
45+
46+
47+
48+

Examples/Completed/concurrency/syntax.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Simple if statement
2+
let temperature = 25
3+
if temperature > 30 {
4+
print("It's hot outside!")
5+
}
6+
7+
// If-else statement
8+
let score = 85
9+
if score >= 90 {
10+
print("Excellent!")
11+
} else if score >= 80 {
12+
print("Good job!")
13+
} else if score >= 70 {
14+
print("Passing")
15+
} else {
16+
print("Needs improvement")
17+
}
18+
19+
// MARK: - Optional Binding with If
20+
21+
// Using if let for optional binding
22+
let possibleNumber = "123"
23+
if let actualNumber = Int(possibleNumber) {
24+
print("The string \"\(possibleNumber)\" has an integer value of \(actualNumber)")
25+
} else {
26+
print("The string \"\(possibleNumber)\" could not be converted to an integer")
27+
}
28+
29+
// Multiple optional bindings
30+
let possibleName: String? = "John"
31+
let possibleAge: Int? = 30
32+
if let name = possibleName, let age = possibleAge {
33+
print("\(name) is \(age) years old")
34+
}
35+
36+
// MARK: - Guard Statements
37+
func greet(person: [String: String]) {
38+
guard let name = person["name"] else {
39+
print("No name provided")
40+
return
41+
}
42+
43+
guard let age = person["age"], let ageInt = Int(age) else {
44+
print("Invalid age provided")
45+
return
46+
}
47+
48+
print("Hello \(name), you are \(ageInt) years old")
49+
}
50+
51+
// MARK: - Switch Statements
52+
// Switch with range matching
53+
let approximateCount = 62
54+
let countedThings = "moons orbiting Saturn"
55+
let naturalCount: String
56+
switch approximateCount {
57+
case 0:
58+
naturalCount = "no"
59+
case 1..<5:
60+
naturalCount = "a few"
61+
case 5..<12:
62+
naturalCount = "several"
63+
case 12..<100:
64+
naturalCount = "dozens of"
65+
case 100..<1000:
66+
naturalCount = "hundreds of"
67+
default:
68+
naturalCount = "many"
69+
}
70+
print("There are \(naturalCount) \(countedThings).")
71+
72+
// Switch with tuple matching
73+
let somePoint = (1, 1)
74+
switch somePoint {
75+
case (0, 0):
76+
print("(0, 0) is at the origin")
77+
case (_, 0):
78+
print("(\(somePoint.0), 0) is on the x-axis")
79+
case (0, _):
80+
print("(0, \(somePoint.1)) is on the y-axis")
81+
case (-2...2, -2...2):
82+
print("(\(somePoint.0), \(somePoint.1)) is inside the box")
83+
default:
84+
print("(\(somePoint.0), \(somePoint.1)) is outside of the box")
85+
}
86+
87+
// Switch with value binding
88+
let anotherPoint = (2, 0)
89+
switch anotherPoint {
90+
case (let x, 0):
91+
print("on the x-axis with an x value of \(x)")
92+
case (0, let y):
93+
print("on the y-axis with a y value of \(y)")
94+
case let (x, y):
95+
print("somewhere else at (\(x), \(y))")
96+
}
97+
98+
// MARK: - Fallthrough
99+
// Using fallthrough in switch
100+
let integerToDescribe = 5
101+
var description = "The number \(integerToDescribe) is"
102+
switch integerToDescribe {
103+
case 2, 3, 5, 7, 11, 13, 17, 19:
104+
description += " a prime number, and also"
105+
fallthrough
106+
default:
107+
description += " an integer."
108+
}
109+
print(description)
110+
111+
// MARK: - Labeled Statements
112+
// Using labeled statements with break
113+
let finalSquare = 25
114+
var board = [Int](repeating: 0, count: finalSquare + 1)
115+
board[03] = 8
116+
board[06] = 11
117+
board[09] = 9
118+
board[10] = 2
119+
board[14] = -10
120+
board[19] = -11
121+
board[22] = -2
122+
board[24] = -8
123+
124+
var square = 0
125+
var diceRoll = 0
126+
while square != finalSquare {
127+
diceRoll += 1
128+
if diceRoll == 7 { diceRoll = 1 }
129+
switch square + diceRoll {
130+
case finalSquare:
131+
break
132+
case let newSquare where newSquare > finalSquare:
133+
continue
134+
default:
135+
square += diceRoll
136+
square += board[square]
137+
}
138+
}
139+
140+
// MARK: - For Loops
141+
// For-in loop with enumerated() to get index and value
142+
print("\n=== For-in with Enumerated ===")
143+
for (index, name) in names.enumerated() {
144+
print("\(index): \(name)")
145+
}
146+
147+
// For-in loop with where clause
148+
print("\n=== For-in with Where Clause ===")
149+
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
150+
for number in numbers where number % 2 == 0 {
151+
print("Even number: \(number)")
152+
}
153+
154+

0 commit comments

Comments
 (0)