summaryrefslogtreecommitdiffstats
path: root/examples/main.rs
blob: 3c301cf3221976694030c8f1ec4ca173c7ca4a32 (plain)
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
extern crate kairos;

fn main() {
    // not sure whether this is actually fast or something, but we don't care here, do we?
    let s = ::std::env::args().skip(1).fold(String::new(), |acc, obj| format!("{} {}", acc, obj));
    let s = s.trim(); // because kairos is not yet whitespace tolerant

    println!("Parsing: '{}'", s);
    match kairos::parser::parse(s) {
        Err(e) => println!("Error -> {:?}", e),
        Ok(kairos::parser::Parsed::TimeType(tt)) => {
            println!("Having TimeType");

            match tt.calculate() {
                Ok(r)  => println!("{:?}", r),
                Err(e) => println!("Error calculating: {:?}", e),
            }
        },
        Ok(kairos::parser::Parsed::Iterator(Ok(ui))) => {
            println!("Having iterator");

            for elem in ui {
                match elem {
                    Ok(r)  => println!("{:?}", r),
                    Err(e) => {
                        println!("Error calculating: {:?}", e);
                        ::std::process::exit(1)
                    }
                }
            }
        },
        Ok(kairos::parser::Parsed::Iterator(Err(e))) => {
            println!("Failed building iterator: {:?}", e);
        },
    }
}