diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-12-18 16:06:10 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-12-18 16:06:10 -0800 |
commit | 469629360dd8aad2f7ca6937cd266b1ab6901bab (patch) | |
tree | c3d733d03bdef29dfdb2b8e19d367ae61894194e /modelica-parser-lalrpop | |
parent | 0777657516a9c3178001752b78d4b6d34dd6dbd1 (diff) | |
download | modelthing-469629360dd8aad2f7ca6937cd266b1ab6901bab.tar.gz modelthing-469629360dd8aad2f7ca6937cd266b1ab6901bab.zip |
manually/naively strip comments from raw .mo files
Diffstat (limited to 'modelica-parser-lalrpop')
-rw-r--r-- | modelica-parser-lalrpop/Cargo.toml | 1 | ||||
-rw-r--r-- | modelica-parser-lalrpop/examples/parse_file.rs | 16 |
2 files changed, 13 insertions, 4 deletions
diff --git a/modelica-parser-lalrpop/Cargo.toml b/modelica-parser-lalrpop/Cargo.toml index 6371bbf..a86788b 100644 --- a/modelica-parser-lalrpop/Cargo.toml +++ b/modelica-parser-lalrpop/Cargo.toml @@ -17,6 +17,7 @@ name = "modelica_parser" [dependencies] lalrpop-util = "^0.12.4" colored = "1.3" +regex = "^0.1" [build-dependencies] lalrpop = "0.12" 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)), } } } |