aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/examples/parse_file.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-17 19:33:11 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-17 19:33:11 -0800
commit2e634496a6f362017d8f5f643d4ad30a3507dff9 (patch)
treef6500ad5f05082a062794f90e2afd1998bb33ec1 /modelica-parser-lalrpop/examples/parse_file.rs
parent9f82aceb9fbdb42f332d68f4a423123bd0788b2c (diff)
downloadmodelthing-2e634496a6f362017d8f5f643d4ad30a3507dff9.tar.gz
modelthing-2e634496a6f362017d8f5f643d4ad30a3507dff9.zip
update/expand parser examples
Diffstat (limited to 'modelica-parser-lalrpop/examples/parse_file.rs')
-rw-r--r--modelica-parser-lalrpop/examples/parse_file.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/modelica-parser-lalrpop/examples/parse_file.rs b/modelica-parser-lalrpop/examples/parse_file.rs
new file mode 100644
index 0000000..1eb4e65
--- /dev/null
+++ b/modelica-parser-lalrpop/examples/parse_file.rs
@@ -0,0 +1,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)),
+ }
+ }
+}