diagnostics_example/
diagnostics_example.rs

1//! Diagnostics functionality usage example
2//!
3//! This example shows how to use bms-rs's diagnostics functionality to parse BMS files and display beautiful diagnostic information.
4
5use bms_rs::bms::prelude::*;
6
7fn main() {
8    // An example BMS file containing warnings
9    let bms_source = r#"#TITLE Test Song
10#ARTIST Test Composer
11#INVALID_COMMAND this will cause a warning
12#TOTAL 100
13
14#00111:01010101
15#00211:02020202
16"#;
17
18    println!("Parsing BMS file and displaying diagnostic information...\n");
19
20    // Parse BMS file
21    let output = parse_bms::<KeyLayoutBeat>(bms_source);
22
23    // Display parsing results
24    println!(
25        "Parsing successful! Found {} warnings",
26        output.warnings.len()
27    );
28
29    // Use diagnostics functionality to output beautiful diagnostic information
30    if !output.warnings.is_empty() {
31        println!("\n=== Diagnostic Information ===");
32        emit_bms_warnings("example.bms", bms_source, &output.warnings);
33    }
34
35    // Can also handle each warning manually
36    println!("\n=== Manual Warning Handling Example ===");
37    let source = SimpleSource::new("example.bms", bms_source);
38    let ariadne_source = ariadne::Source::from(bms_source);
39
40    for warning in &output.warnings {
41        let report = warning.to_report(&source);
42        let _ = report.print(("example.bms".to_string(), ariadne_source.clone()));
43    }
44
45    println!("\nBMS parsing completed!");
46}