Skip to main content

errors/
errors.rs

1use hypen_parser::parse_component;
2
3fn main() {
4    println!("=== Hypen Parser Error Examples ===\n");
5
6    // Example 1: Unclosed string
7    println!("1. Unclosed string:");
8    let input1 = r#"Text("Hello"#;
9    match parse_component(input1) {
10        Ok(_) => println!("  ✓ Parsed successfully (unexpected)"),
11        Err(errors) => {
12            println!("  ✗ Parse failed:");
13            for error in errors {
14                println!("    {}", error);
15            }
16        }
17    }
18
19    println!("\n2. Unclosed parentheses:");
20    let input2 = r#"Text("Hello""#;
21    match parse_component(input2) {
22        Ok(_) => println!("  ✓ Parsed successfully (unexpected)"),
23        Err(errors) => {
24            println!("  ✗ Parse failed:");
25            for error in errors {
26                println!("    {}", error);
27            }
28        }
29    }
30
31    println!("\n3. Unclosed block:");
32    let input3 = r#"
33        Column {
34            Text("Hello")
35    "#;
36    match parse_component(input3) {
37        Ok(_) => println!("  ✓ Parsed successfully (unexpected)"),
38        Err(errors) => {
39            println!("  ✗ Parse failed:");
40            for error in errors {
41                println!("    {}", error);
42            }
43        }
44    }
45
46    println!("\n4. Invalid syntax:");
47    let input4 = r#"Text(((("#;
48    match parse_component(input4) {
49        Ok(_) => println!("  ✓ Parsed successfully (unexpected)"),
50        Err(errors) => {
51            println!("  ✗ Parse failed:");
52            for error in errors {
53                println!("    {}", error);
54            }
55        }
56    }
57
58    println!("\n5. Missing closing brace:");
59    let input5 = r#"
60        Column {
61            Row {
62                Text("Inside")
63
64        }
65    "#;
66    match parse_component(input5) {
67        Ok(_) => println!("  ✓ Parsed successfully (unexpected)"),
68        Err(errors) => {
69            println!("  ✗ Parse failed:");
70            for error in errors {
71                println!("    {}", error);
72            }
73        }
74    }
75
76    println!("\n6. Valid input (for comparison):");
77    let input6 = r#"
78        Column {
79            Text("Hello")
80        }
81    "#;
82    match parse_component(input6) {
83        Ok(component) => println!("  ✓ Successfully parsed component: {}", component.name),
84        Err(errors) => {
85            println!("  ✗ Parse failed (unexpected):");
86            for error in errors {
87                println!("    {}", error);
88            }
89        }
90    }
91}