Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Preprocessor for CheckCodePreprocessor {
"check-code"
}

fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book> {
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book> {
// Check if book.toml is approved
let book_toml_path = ctx.root.join("book.toml");

Expand Down Expand Up @@ -115,9 +115,11 @@ impl Preprocessor for CheckCodePreprocessor {
let mut failed_files = HashSet::new();
let mut stats: HashMap<String, usize> = HashMap::new();

// Process each chapter in the book
for section in &book.sections {
if let BookItem::Chapter(chapter) = section {
// Process all chapters recursively (including nested ones)
// Using Book::for_each_mut() is the standard pattern in mdBook preprocessors
// and automatically handles traversal of chapter.sub_items at all depths
book.for_each_mut(|item| {
if let BookItem::Chapter(chapter) = item {
if let Some(chapter_path) = &chapter.path {
let full_path = src_dir.join(chapter_path);

Expand All @@ -136,7 +138,7 @@ impl Preprocessor for CheckCodePreprocessor {
}
}
}
}
});

if !failed_files.is_empty() {
let now = Local::now();
Expand Down
12 changes: 8 additions & 4 deletions tests/fixtures/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Summary

- [Introduction](intro.md)
- [Parasol C Basic Example](basic.md)
- [Parasol C Propagate Example](propagate.md)
- [Plain C Example](c_example.md)
- [TypeScript Example](typescript_example.md)
- [Parasol C Examples](parasol_examples/README.md)
- [Basic Example](parasol_examples/basic.md)
- [Propagate Example](parasol_examples/propagate.md)
- [Other Languages](other_langs/README.md)
- [C Examples](other_langs/c_examples/README.md)
- [Plain C Example](other_langs/c_examples/c_example.md)
- [TypeScript Examples](other_langs/ts_examples/README.md)
- [TypeScript Example](other_langs/ts_examples/typescript_example.md)
- [Solidity Example](solidity_example.md)
<!-- Uncomment to test error output: -->
<!-- - [Test Error](test_error.md) -->
16 changes: 16 additions & 0 deletions tests/fixtures/src/other_langs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Other Languages

This section demonstrates code validation for non-Parasol languages at depth level 1.

Code validation works with multiple language configurations. Here is a simple C example:

```c
struct Point {
int x;
int y;
};

int add_points(struct Point p1, struct Point p2) {
return p1.x + p2.x + p1.y + p2.y;
}
```
16 changes: 16 additions & 0 deletions tests/fixtures/src/other_langs/c_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# C Examples

This section demonstrates plain C code validation at depth level 2.

Standard C code can be validated without FHE annotations:

```c
typedef struct {
int value;
char label[32];
} Item;

int compare_items(Item a, Item b) {
return a.value - b.value;
}
```
18 changes: 18 additions & 0 deletions tests/fixtures/src/other_langs/ts_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# TypeScript Examples

This section demonstrates TypeScript code validation at depth level 2.

TypeScript type checking works seamlessly with the preprocessor:

```typescript
interface Config {
host: string;
port: number;
secure?: boolean;
}

function getUrl(config: Config): string {
const protocol = config.secure ? 'https' : 'http';
return `${protocol}://${config.host}:${config.port}`;
}
```
13 changes: 13 additions & 0 deletions tests/fixtures/src/parasol_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Parasol C Examples

This section demonstrates Parasol C code validation at depth level 1.

The following examples show how to write FHE programs using Parasol C.

Here is a simple function to test code validation at this depth:

```parasol-c
[[clang::fhe_program]] uint8_t simple_add(uint8_t x, uint8_t y) {
return x + y;
}
```
Loading