aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/mt-tool.rs
blob: d71a2ebaefe602c1f7ecd3ecb0a8efcbb59f07f6 (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
37
38
39
40
41
42
43
44
45
46
47

extern crate modelthing;
extern crate rustc_serialize;
extern crate docopt;

use modelthing::modelica_parser;
use docopt::Docopt;
use std::env;
use std::io::Read;
use std::fs::File;
use std::time::Instant;


fn main() {
    let args: Args = Docopt::new(USAGE)
                        .and_then(|d| d.argv(env::args()).decode())
                        .unwrap_or_else(|e| e.exit());

    for input in &args.arg_inputs {
        let mut s = String::new();
        if let Err(err) = File::open(input).and_then(|mut f| f.read_to_string(&mut s)) {
            println!("Input `{}`: I/O Error {}",
                     input, err);
            continue;
        }

        let time_stamp = Instant::now();
        let result = modelica_parser::parse_model(&s);
        let elapsed = time_stamp.elapsed();
        let elapsed = elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1000_000_000.0;

        match result {
            Ok(_) => println!("Input `{}` ({}s): OK", input, elapsed),
            Err(err) => println!("Input `{}` ({}s): parse error {:?}", input, elapsed, err),
        }
    }
}

const USAGE: &'static str = "
Usage: modelthing-modelica <inputs>...
Parses each input file.
";

#[derive(Debug, RustcDecodable)]
struct Args {
    arg_inputs: Vec<String>,
}