pretty_errors/
pretty_errors.rs

1use hypen_parser::{parse_component, print_parse_errors};
2
3fn main() {
4    println!("=== Hypen Parser Error Examples with Ariadne ===\n");
5
6    // Example 1: Unclosed string
7    println!("Example 1: Unclosed string\n");
8    let input1 = r#"Text("Hello"#;
9    if let Err(errors) = parse_component(input1) {
10        print_parse_errors("example.hypen", input1, &errors);
11    }
12
13    println!("\n{}\n", "=".repeat(60));
14
15    // Example 2: Unclosed parentheses
16    println!("Example 2: Unclosed parentheses\n");
17    let input2 = r#"Text("Hello""#;
18    if let Err(errors) = parse_component(input2) {
19        print_parse_errors("example.hypen", input2, &errors);
20    }
21
22    println!("\n{}\n", "=".repeat(60));
23
24    // Example 3: Unclosed block
25    println!("Example 3: Unclosed block\n");
26    let input3 = r#"Column {
27    Text("Hello")
28    Row {
29        Text("World")
30"#;
31    if let Err(errors) = parse_component(input3) {
32        print_parse_errors("example.hypen", input3, &errors);
33    }
34
35    println!("\n{}\n", "=".repeat(60));
36
37    // Example 4: Invalid syntax in arguments
38    println!("Example 4: Invalid syntax in arguments\n");
39    let input4 = r#"Text(key: , value: 123)"#;
40    if let Err(errors) = parse_component(input4) {
41        print_parse_errors("example.hypen", input4, &errors);
42    }
43
44    println!("\n{}\n", "=".repeat(60));
45
46    // Example 5: Complex nested error
47    println!("Example 5: Complex nested error\n");
48    let input5 = r#"Column {
49    Text("Header")
50        .fontSize(18)
51        .color(blue)
52
53    Row {
54        Button("Sign In")
55            .padding(16
56        Text("Footer")
57    }
58}
59"#;
60    if let Err(errors) = parse_component(input5) {
61        print_parse_errors("example.hypen", input5, &errors);
62    }
63
64    println!("\n{}\n", "=".repeat(60));
65
66    // Example 6: Show a successful parse
67    println!("Example 6: Valid input (success)\n");
68    let input6 = r#"Column {
69    Text("Hello")
70        .fontSize(18)
71}"#;
72    match parse_component(input6) {
73        Ok(component) => println!("✓ Successfully parsed component: {}\n", component.name),
74        Err(errors) => print_parse_errors("example.hypen", input6, &errors),
75    }
76}