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


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...");
        ::std::process::exit(-1);
    }

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

        let striped = modelica_parser::strip_comments(&raw);
        let result = modelica_parser::parse_model(&striped);

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