aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/src
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-19 00:46:53 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-19 00:46:53 -0800
commitaefce10b8f05dc52017beb1d422ce7b2b97bd6a5 (patch)
treee076218f621f71cf5b5074c3ffdf485fb8271ca2 /modelica-parser-lalrpop/src
parentb41f79765ecc80454e5f964de34ed73fefa15e7c (diff)
downloadmodelthing-aefce10b8f05dc52017beb1d422ce7b2b97bd6a5.tar.gz
modelthing-aefce10b8f05dc52017beb1d422ce7b2b97bd6a5.zip
parser: make strip comments a function
Diffstat (limited to 'modelica-parser-lalrpop/src')
-rw-r--r--modelica-parser-lalrpop/src/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/modelica-parser-lalrpop/src/lib.rs b/modelica-parser-lalrpop/src/lib.rs
index a109607..0b94c35 100644
--- a/modelica-parser-lalrpop/src/lib.rs
+++ b/modelica-parser-lalrpop/src/lib.rs
@@ -1,13 +1,23 @@
extern crate lalrpop_util;
extern crate colored;
+extern crate regex;
pub mod parser;
pub mod ast;
use colored::*;
use lalrpop_util::ParseError;
+use regex::Regex;
+pub fn strip_comments(raw: &str) -> String {
+ // TODO: shouldn't recompile regex on every function call
+
+ // Match on comments:
+ // (?m) sets multi-line mode
+ let comment_re = Regex::new(r"(?m)(//.*)$").unwrap();
+ comment_re.replace_all(&raw, "")
+}
fn pp_segment(raw: &str, start: usize, end: usize) -> String {
let mut line_start = 0;