pub fn parse_scene(text: &str) -> SceneModelExpand description
Parse .tscn/.tres text into a SceneModel. Pure, never panics, never returns Err.
Examples found in repository?
examples/scene_corpus.rs (line 49)
31fn main() {
32 let args: Vec<String> = std::env::args().skip(1).collect();
33 let dir = args
34 .first()
35 .cloned()
36 .expect("usage: scene_corpus <dir> [--show]");
37 let show = args.iter().any(|a| a == "--show");
38
39 let mut files = Vec::new();
40 collect(Path::new(&dir), &mut files);
41 files.sort();
42
43 let (mut clean, mut with_problems, mut total_problems, mut nodes_total) = (0usize, 0, 0, 0);
44 let mut panics = Vec::new();
45 for path in &files {
46 let Ok(src) = std::fs::read_to_string(path) else {
47 continue; // non-UTF-8 / unreadable — not a text scene
48 };
49 match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| parse_scene(&src))) {
50 Ok(m) => {
51 nodes_total += m.nodes.len();
52 if m.problems.is_empty() {
53 clean += 1;
54 } else {
55 with_problems += 1;
56 total_problems += m.problems.len();
57 if show {
58 println!("\n{} ({} problems)", path.display(), m.problems.len());
59 for p in &m.problems {
60 println!(" {p:?}");
61 }
62 }
63 }
64 }
65 Err(_) => panics.push(path.clone()),
66 }
67 }
68
69 println!(
70 "\n=== scene corpus: {dir} ===\n files: {}\n clean: {clean}\n with problems: {with_problems} ({total_problems} problems)\n nodes parsed: {nodes_total}\n panics: {}",
71 files.len(),
72 panics.len()
73 );
74 for p in &panics {
75 println!(" PANIC: {}", p.display());
76 }
77}