1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! # kiutils-kicad
//!
//! Typed KiCad file document layer built on top of `kiutils-sexpr`.
//!
//! If you want stable end-user imports, use [`kiutils-rs`](https://docs.rs/kiutils-rs).
//! This crate exposes the implementation-layer API and additional file families.
//!
//! ## Scope
//! - `.kicad_pcb`
//! - `.kicad_mod`
//! - `.kicad_sch`
//! - `.kicad_sym`
//! - `fp-lib-table`
//! - `sym-lib-table`
//! - `.kicad_dru`
//! - `.kicad_pro`
//! - `.kicad_wks`
//!
//! ## Core behavior
//! - Default write mode is lossless (`WriteMode::Lossless`)
//! - Unknown tokens are captured on typed ASTs (`unknown_nodes`, `unknown_fields`)
//! - `write_mode(..., WriteMode::Canonical)` available for normalized output
//! - Version diagnostics produced post-parse for forward-compat signaling
//!
//! Evidence:
//! - Round-trip + unknown preservation tests:
//! <https://github.com/Milind220/kiutils-rs/blob/main/crates/kiutils_kicad/tests/integration.rs>
//! - CLI contract tests (`kiutils-inspect`):
//! <https://github.com/Milind220/kiutils-rs/blob/main/crates/kiutils_kicad/tests/inspect_cli.rs>
//!
//! ## Quickstart
//! ```rust,no_run
//! use kiutils_kicad::{SchematicFile, WriteMode};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let doc = SchematicFile::read("input.kicad_sch")?;
//! doc.write_mode("output.kicad_sch", WriteMode::Lossless)?;
//! Ok(())
//! }
//! ```
//!
//! Policy notes:
//! - AST `*_count` fields are convenience counters, not strict stability promises.
//! - Unknown-token diagnostics are developer-facing; summarize before showing end users.
//! - `.kicad_dru` rule conditions are preserved as strings in v1.
//!
//! ## Token alias policy
//!
//! KiCad file formats have evolved over major versions, sometimes renaming root
//! tokens or restructuring S-expression nodes. This crate follows a consistent
//! policy for handling these differences:
//!
//! | Format | Modern token | Legacy alias | Behavior |
//! |--------|-------------|--------------|----------|
//! | PCB | `kicad_pcb` | _(none)_ | Only modern accepted |
//! | Footprint | `footprint` | `module` | Both accepted; `legacy_root` diagnostic emitted |
//! | Schematic | `kicad_sch` | _(none)_ | Only modern accepted |
//! | Symbol lib | `kicad_symbol_lib` | _(none)_ | Only modern accepted |
//! | Worksheet | `kicad_wks` | `page_layout` | Both accepted; `legacy_root` diagnostic emitted |
//! | Design rules | `kicad_dru` | _(rootless)_ | Rootless format accepted |
//! | Lib tables | `fp_lib_table` / `sym_lib_table` | _(none)_ | Only modern accepted |
//!
//! ### Parser guarantees
//!
//! 1. **Lossless round-trip**: Writing a parsed file with `WriteMode::Lossless` produces
//! byte-identical output to the original input, including whitespace and comments.
//! 2. **Unknown token preservation**: Any S-expression node not recognized by the typed
//! AST parser is captured in `unknown_nodes` / `unknown_fields` vectors and preserved
//! through round-trip writes.
//! 3. **Forward compatibility**: Files from newer KiCad versions parse without error;
//! unrecognized tokens land in unknown vectors and a `future_format` diagnostic is
//! emitted when the version number exceeds the known range.
//! 4. **Legacy compatibility**: Files using legacy root tokens (see table above) parse
//! in compatibility mode with a `legacy_root` diagnostic to inform callers.
//! 5. **Typed AST is read-only over CST**: The typed AST is derived from the CST on parse.
//! Mutations go through document setter APIs that modify the CST directly, then
//! re-derive the AST, ensuring CST remains the source of truth.
pub use ;
pub use ;
pub use ;
pub use Error;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use WriteMode;