lron_dump/
lron_dump.rs

1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7//! Dump lron file. Allow validating the grammar.
8
9extern crate lrcat;
10
11use std::env;
12use std::fs::File;
13use std::io::Read;
14
15/// Parse the lron file and output it's parsed content or an error.
16/// @return an error in case of IO error.
17fn dump_lron(filename: &str) -> std::io::Result<()> {
18    let mut file = File::open(filename).expect("Unknown file");
19
20    let mut buffer = String::new();
21    file.read_to_string(&mut buffer)?;
22
23    let o = lrcat::lron::Object::from_string(&buffer);
24    match o {
25        Ok(ref o) => {
26            println!("Result: {:?}", o);
27        }
28        Err(e) => println!("Error parsing file {}: {:?}", filename, e),
29    }
30    Ok(())
31}
32
33fn main() {
34    let args: Vec<String> = env::args().collect();
35    if args.len() < 2 {
36        return;
37    }
38
39    let mut iter = args.iter();
40    iter.next();
41    for filename in iter {
42        if let Err(err) = dump_lron(filename) {
43            println!("Error dumping lron: {} {}", filename, err);
44        }
45    }
46}