From c0a9d990f943867b417091cc7ffc3c31c114995a Mon Sep 17 00:00:00 2001 From: Graham Littlewood Date: Mon, 13 Apr 2020 13:24:13 -0400 Subject: [PATCH] Fix multi-line captures --- src/commands/cmd_macro.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/cmd_macro.rs b/src/commands/cmd_macro.rs index 96ac026..6f9fd38 100644 --- a/src/commands/cmd_macro.rs +++ b/src/commands/cmd_macro.rs @@ -10,7 +10,7 @@ extern crate serde_json; use serde_json::Result; extern crate regex; -use regex::{Regex, Match}; +use regex::{Regex, RegexBuilder, Match}; use core::option::Option; use std::collections::HashMap; @@ -88,8 +88,12 @@ impl CmdMacro { let macros: HashMap> = serde_json::from_reader(reader).unwrap_or(HashMap::>::new()); return CmdMacro { format: - Regex::new(r#"^!macro\s+([A-Za-z0-9]+|"[^\s]+"|'[^\s]+')(?:\s+([A-Za-z0-9]+|"[^\s]+"|'[^\s]+')\s+(.+))?"#) - .unwrap(), + RegexBuilder::new(r#"^!macro\s+([A-Za-z0-9]+|"[^\s]+"|'[^\s]+')(?:\s+([A-Za-z0-9]+|"[^\s]+"|'[^\s]+')\s+(.+))?"#) + .multi_line(true) + .dot_matches_new_line(true) + .case_insensitive(true) + .build() + .unwrap(), macros: macros, }; } @@ -148,7 +152,7 @@ impl CmdMacro { } fn save_json(&self) { - let mut file = OpenOptions::new() + let file = OpenOptions::new() .write(true) .open(MACRO_PATH) .unwrap();