aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2017-01-07 21:46:22 -0800
committerbnewbold <bnewbold@robocracy.org>2017-01-07 21:46:24 -0800
commitf2c1f1c13772145acaecb1ebf9b4cafcacb98131 (patch)
tree8def62d9d0f2beb1d42a87ff3af07e49330f7c10
parentf606f6acb36e028e66fa4225ed7d46d2bd653f6f (diff)
downloadmodelthing-f2c1f1c13772145acaecb1ebf9b4cafcacb98131.tar.gz
modelthing-f2c1f1c13772145acaecb1ebf9b4cafcacb98131.zip
parser: statically compile regex w/ lazy_static
As per regex library's documentation
-rw-r--r--modelica-parser-lalrpop/Cargo.toml1
-rw-r--r--modelica-parser-lalrpop/src/lib.rs9
2 files changed, 6 insertions, 4 deletions
diff --git a/modelica-parser-lalrpop/Cargo.toml b/modelica-parser-lalrpop/Cargo.toml
index 42c6357..6e4b196 100644
--- a/modelica-parser-lalrpop/Cargo.toml
+++ b/modelica-parser-lalrpop/Cargo.toml
@@ -18,6 +18,7 @@ name = "modelica_parser"
lalrpop-util = "^0.12.4"
colored = "1.3"
regex = "^0.1"
+lazy_static = "^0.2"
[build-dependencies]
lalrpop = "0.12"
diff --git a/modelica-parser-lalrpop/src/lib.rs b/modelica-parser-lalrpop/src/lib.rs
index b515d73..ed07ca2 100644
--- a/modelica-parser-lalrpop/src/lib.rs
+++ b/modelica-parser-lalrpop/src/lib.rs
@@ -2,6 +2,7 @@
extern crate lalrpop_util;
extern crate colored;
extern crate regex;
+#[macro_use] extern crate lazy_static;
mod parser;
mod ast;
@@ -20,12 +21,12 @@ pub use parser::{
};
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, "")
+ lazy_static! {
+ static ref RE: Regex = Regex::new(r"(?m)(//.*)$").unwrap();
+ }
+ RE.replace_all(&raw, "")
}
fn pp_segment(raw: &str, start: usize, end: usize) -> String {