diff --git a/src/preprocessor.rs b/src/preprocessor.rs index cf0f18c..c65245b 100644 --- a/src/preprocessor.rs +++ b/src/preprocessor.rs @@ -61,7 +61,7 @@ impl Preprocessor for CheckCodePreprocessor { "check-code" } - fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result { + fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result { // Check if book.toml is approved let book_toml_path = ctx.root.join("book.toml"); @@ -115,9 +115,11 @@ impl Preprocessor for CheckCodePreprocessor { let mut failed_files = HashSet::new(); let mut stats: HashMap = 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); @@ -136,7 +138,7 @@ impl Preprocessor for CheckCodePreprocessor { } } } - } + }); if !failed_files.is_empty() { let now = Local::now(); diff --git a/tests/fixtures/src/SUMMARY.md b/tests/fixtures/src/SUMMARY.md index 1ba61d5..0e7072c 100644 --- a/tests/fixtures/src/SUMMARY.md +++ b/tests/fixtures/src/SUMMARY.md @@ -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) diff --git a/tests/fixtures/src/other_langs/README.md b/tests/fixtures/src/other_langs/README.md new file mode 100644 index 0000000..ece8f96 --- /dev/null +++ b/tests/fixtures/src/other_langs/README.md @@ -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; +} +``` diff --git a/tests/fixtures/src/other_langs/c_examples/README.md b/tests/fixtures/src/other_langs/c_examples/README.md new file mode 100644 index 0000000..0fffd84 --- /dev/null +++ b/tests/fixtures/src/other_langs/c_examples/README.md @@ -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; +} +``` diff --git a/tests/fixtures/src/c_example.md b/tests/fixtures/src/other_langs/c_examples/c_example.md similarity index 100% rename from tests/fixtures/src/c_example.md rename to tests/fixtures/src/other_langs/c_examples/c_example.md diff --git a/tests/fixtures/src/other_langs/ts_examples/README.md b/tests/fixtures/src/other_langs/ts_examples/README.md new file mode 100644 index 0000000..74246bf --- /dev/null +++ b/tests/fixtures/src/other_langs/ts_examples/README.md @@ -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}`; +} +``` diff --git a/tests/fixtures/src/typescript_example.md b/tests/fixtures/src/other_langs/ts_examples/typescript_example.md similarity index 100% rename from tests/fixtures/src/typescript_example.md rename to tests/fixtures/src/other_langs/ts_examples/typescript_example.md diff --git a/tests/fixtures/src/parasol_examples/README.md b/tests/fixtures/src/parasol_examples/README.md new file mode 100644 index 0000000..451989d --- /dev/null +++ b/tests/fixtures/src/parasol_examples/README.md @@ -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; +} +``` diff --git a/tests/fixtures/src/basic.md b/tests/fixtures/src/parasol_examples/basic.md similarity index 100% rename from tests/fixtures/src/basic.md rename to tests/fixtures/src/parasol_examples/basic.md diff --git a/tests/fixtures/src/propagate.md b/tests/fixtures/src/parasol_examples/propagate.md similarity index 100% rename from tests/fixtures/src/propagate.md rename to tests/fixtures/src/parasol_examples/propagate.md