diff options
Diffstat (limited to 'modelica-parser-lalrpop')
-rw-r--r-- | modelica-parser-lalrpop/Cargo.toml | 1 | ||||
-rw-r--r-- | modelica-parser-lalrpop/src/lib.rs | 9 |
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 { |