Skip to content

Commit 4729ad7

Browse files
committed
fixing main documentation
1 parent a0aec7e commit 4729ad7

4 files changed

Lines changed: 63 additions & 32 deletions

File tree

Scripts/validate-docs.sh

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,27 +316,54 @@ validate_code_examples() {
316316

317317
echo -e "${BLUE}📄 Processing: $relative_path${NC}"
318318

319-
# Extract Swift code blocks using awk
319+
# Extract Swift code blocks using awk, respecting skip markers
320320
awk -v temp_dir="$temp_dir" -v file_base="$(basename "$file" .md)" '
321-
BEGIN { block_num = 0 }
321+
BEGIN { block_num = 0; skip_block = 0 }
322+
323+
# Check for skip markers in HTML comments
324+
/<!-- (skip-test|no-test|incomplete|example-only) -->/ {
325+
skip_block = 1
326+
next
327+
}
328+
322329
/^```swift/ {
323330
in_swift = 1
324-
block_num++
325-
output_file = temp_dir "/" file_base "_" block_num ".swift"
326-
print "import Foundation" > output_file
327-
print "import SyntaxKit" >> output_file
328-
print "" >> output_file
331+
332+
# Check preceding lines (up to 3 lines back) for skip markers
333+
for (i = NR - 3; i < NR; i++) {
334+
if (i > 0 && lines[i] ~ /<!-- (skip-test|no-test|incomplete|example-only) -->/) {
335+
skip_block = 1
336+
break
337+
}
338+
}
339+
340+
if (!skip_block) {
341+
block_num++
342+
output_file = temp_dir "/" file_base "_" block_num ".swift"
343+
print "import Foundation" > output_file
344+
print "import SyntaxKit" >> output_file
345+
print "" >> output_file
346+
}
329347
next
330348
}
331349
/^```$/ && in_swift {
332350
in_swift = 0
333-
close(output_file)
334-
print output_file
351+
if (!skip_block && output_file) {
352+
close(output_file)
353+
print output_file
354+
}
355+
skip_block = 0
356+
output_file = ""
335357
next
336358
}
337-
in_swift {
338-
print $0 >> output_file
359+
in_swift && !skip_block {
360+
if (output_file) {
361+
print $0 >> output_file
362+
}
339363
}
364+
365+
# Store lines for lookback
366+
{ lines[NR] = $0 }
340367
' "$file"
341368
}
342369

Sources/SyntaxKit/Documentation.docc/Documentation.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,30 @@ let structExample = Struct("BlackjackCard") {
129129
Variable(.let, name: "second", type: "Int?")
130130
}
131131

132-
ComputedProperty("values") {
132+
ComputedProperty("values", type: "Values") {
133133
Switch("self") {
134134
SwitchCase(".ace") {
135135
Return {
136136
Init("Values") {
137-
Parameter(name: "first", value: "1")
138-
Parameter(name: "second", value: "11")
137+
138+
ParameterExp(name: "first", value: Literal.integer(1))
139+
ParameterExp(name: "second", value: Literal.integer(11))
139140
}
140141
}
141142
}
142143
SwitchCase(".jack", ".queen", ".king") {
143144
Return {
144145
Init("Values") {
145-
Parameter(name: "first", value: "10")
146-
Parameter(name: "second", value: "nil")
146+
ParameterExp(name: "first", value: Literal.integer(10))
147+
ParameterExp(name: "second", value: Literal.nil)
147148
}
148149
}
149150
}
150151
Default {
151152
Return {
152153
Init("Values") {
153-
Parameter(name: "first", value: "self.rawValue")
154-
Parameter(name: "second", value: "nil")
154+
ParameterExp(name: "first", value: VariableExp("self.rawValue"))
155+
ParameterExp(name: "second", value: Literal.nil)
155156
}
156157
}
157158
}
@@ -169,11 +170,19 @@ let structExample = Struct("BlackjackCard") {
169170
Line("BlackjackCard properties and methods")
170171
}
171172

172-
ComputedProperty("description") {
173-
VariableDecl(.var, name: "output", equals: "\"suit is \\(suit.rawValue),\"")
174-
PlusAssign("output", "\" value is \\(rank.values.first)\"")
173+
ComputedProperty("description", type: "String") {
174+
Variable(.var, name: "output", equals: "\"suit is \\(suit.rawValue),\"")
175+
Infix(
176+
.plusAssign,
177+
lhs: VariableExp("output"),
178+
rhs: Literal.string("\" value is \\(rank.values.first)\"")
179+
)
175180
If(Let("second", "rank.values.second"), then: {
176-
PlusAssign("output", "\" or \\(second)\"")
181+
Infix(
182+
.plusAssign,
183+
lhs: VariableExp("output"),
184+
rhs: Literal.string("\" or \\(second)\"")
185+
)
177186
})
178187
Return {
179188
VariableExp("output")
@@ -339,7 +348,7 @@ struct MembersMacro: MemberMacro {
339348
```
340349

341350
**SyntaxKit Approach (Clean and readable):**
342-
<!-- example-only -->
351+
<!-- skip-test -->
343352
```swift
344353
struct MembersMacro: MemberMacro {
345354
static func expansion(
@@ -356,8 +365,7 @@ struct MembersMacro: MemberMacro {
356365
for variable in variables {
357366
Parameter(variable.name, type: variable.type)
358367
}
359-
}
360-
.body {
368+
} _: {
361369
for variable in variables {
362370
Assignment("self.\(variable.name)", variable.name)
363371
}
@@ -396,6 +404,7 @@ struct MembersMacro: MemberMacro {
396404

397405
**Generated code performance is identical to hand-written Swift.** SyntaxKit operates at compile-time only:
398406

407+
<!-- skip-test -->
399408
```swift
400409
// SyntaxKit-generated code
401410
struct User: Equatable {

Sources/SyntaxKit/Documentation.docc/Examples/EnumGenerator.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,3 @@ SyntaxKit's enum generator transforms tedious manual maintenance into reliable a
446446
- **Improved developer experience** and satisfaction
447447

448448
The approach scales from small personal projects to enterprise applications with hundreds of API endpoints. Once implemented, enum maintenance becomes completely automated, freeing developers to focus on building great features instead of maintaining boilerplate code.
449-
450-
## Related Examples
451-
452-
- ``Examples/API-Endpoints`` - Simple endpoint enum generation
453-
- ``Examples/Error-Handling`` - Complex error enum with associated values
454-
- ``Examples/Configuration-Driven`` - Multiple enum generation from single config
455-
- ``Tutorials/Code-Generation`` - Comprehensive code generation patterns

Sources/SyntaxKit/Expressions/Infix.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public struct Infix: CodeBlock, ExprCodeBlock {
3737
case lessThan = "<"
3838
case equal = "=="
3939
case notEqual = "!="
40+
case plusAssign = "+="
41+
case minusAssign = "-="
4042

4143
/// The string representation of the operator.
4244
public var symbol: String {

0 commit comments

Comments
 (0)