aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/examples
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-18 16:06:10 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-18 16:06:10 -0800
commit469629360dd8aad2f7ca6937cd266b1ab6901bab (patch)
treec3d733d03bdef29dfdb2b8e19d367ae61894194e /modelica-parser-lalrpop/examples
parent0777657516a9c3178001752b78d4b6d34dd6dbd1 (diff)
downloadmodelthing-469629360dd8aad2f7ca6937cd266b1ab6901bab.tar.gz
modelthing-469629360dd8aad2f7ca6937cd266b1ab6901bab.zip
manually/naively strip comments from raw .mo files
Diffstat (limited to 'modelica-parser-lalrpop/examples')
-rw-r--r--modelica-parser-lalrpop/examples/parse_file.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/modelica-parser-lalrpop/examples/parse_file.rs b/modelica-parser-lalrpop/examples/parse_file.rs
index b3d6913..53da285 100644
--- a/modelica-parser-lalrpop/examples/parse_file.rs
+++ b/modelica-parser-lalrpop/examples/parse_file.rs
@@ -1,15 +1,20 @@
extern crate modelica_parser;
+extern crate regex;
use std::env;
use std::io::Read;
use std::fs::File;
use std::process::exit;
+use regex::Regex;
fn main() {
let args: Vec<String> = env::args().collect();
+ // Match on comments:
+ // (?m) sets multi-line mode
+ let comment_re = Regex::new(r"(?m)(//.*)$").unwrap();
if args.len() <= 1 {
println!("I'm a modelica parser! Pass me one or more files to parse...");
@@ -17,18 +22,21 @@ fn main() {
}
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)) {
+ 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 result = modelica_parser::parser::parse_file(&s);
+ // Strip comments manually
+ let striped = comment_re.replace_all(&raw, "");
+
+ let result = modelica_parser::parser::parse_file(&striped);
match result {
Ok(_) => println!("=== {}: OK", input),
- Err(err) => println!("=== {}: ERROR\n{}", input, modelica_parser::pp_parseerror(&s, err)),
+ Err(err) => println!("=== {}: ERROR\n{}", input, modelica_parser::pp_parseerror(&striped, err)),
}
}
}