aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/examples/parse_file.rs
blob: 1eb4e6544c6e9c8e07fc5464bbf481ec66db3ea5 (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

extern crate modelica_parser;

use std::env;
use std::io::Read;
use std::fs::File;
use std::process::exit;


fn main() {

    let args: Vec<String> = env::args().collect();

    if args.len() <= 1 {
        println!("I'm a modelica parser! Pass me one or more files to parse...");
        exit(-1);
    }

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

        let result = modelica_parser::parser::parse_model(&s);

        match result {
            Ok(_) => println!("=== {}: OK", input),
            Err(err) => println!("=== {}: ERROR\n{}", input, modelica_parser::pp_parseerror(&s, err)),
        }
    }
}