From f264a289fe0d504a99c01d5787edb92af8f6ca91 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 18 Sep 2016 14:24:44 -0700 Subject: work on a minimal modelica parser+ast --- src/bin/modelthing-modelica.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ src/bin/parse_pascal.rs | 47 ------------------------------------------ 2 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 src/bin/modelthing-modelica.rs delete mode 100644 src/bin/parse_pascal.rs (limited to 'src/bin') diff --git a/src/bin/modelthing-modelica.rs b/src/bin/modelthing-modelica.rs new file mode 100644 index 0000000..a8fa9be --- /dev/null +++ b/src/bin/modelthing-modelica.rs @@ -0,0 +1,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_file(&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 ... +Parses each input file. +"; + +#[derive(Debug, RustcDecodable)] +struct Args { + arg_inputs: Vec, +} diff --git a/src/bin/parse_pascal.rs b/src/bin/parse_pascal.rs deleted file mode 100644 index 7b08f36..0000000 --- a/src/bin/parse_pascal.rs +++ /dev/null @@ -1,47 +0,0 @@ - -extern crate modelthing; -extern crate rustc_serialize; -extern crate docopt; - -use modelthing::pascal; -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 = pascal::parse_file(&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-pascal ... -Parses each input file. -"; - -#[derive(Debug, RustcDecodable)] -struct Args { - arg_inputs: Vec, -} -- cgit v1.2.3