@@ -14,6 +14,7 @@ use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
1414use  crate :: header:: cfg:: parse_cfg_name_directive; 
1515use  crate :: header:: cfg:: MatchOutcome ; 
1616use  crate :: header:: needs:: CachedNeedsConditions ; 
17+ use  crate :: util:: static_regex; 
1718use  crate :: { extract_cdb_version,  extract_gdb_version} ; 
1819
1920mod  cfg; 
@@ -1186,11 +1187,11 @@ impl Config {
11861187        } 
11871188    } 
11881189
1189-     fn  parse_custom_normalization ( & self ,  mut   line :  & str ,  prefix :  & str )  -> Option < ( String ,  String ) >  { 
1190+     fn  parse_custom_normalization ( & self ,  line :  & str ,  prefix :  & str )  -> Option < ( String ,  String ) >  { 
11901191        if  parse_cfg_name_directive ( self ,  line,  prefix) . outcome  == MatchOutcome :: Match  { 
1191-             let  from =  parse_normalization_string ( & mut   line) ? ; 
1192-             let  to =  parse_normalization_string ( & mut   line) ? ; 
1193-             Some ( ( from ,  to ) ) 
1192+             let  ( regex ,  replacement )  =  parse_normalize_rule ( line) 
1193+                  . unwrap_or_else ( ||  panic ! ( "couldn't parse custom normalization rule: `{ line}`" ) ) ; 
1194+             Some ( ( regex ,  replacement ) ) 
11941195        }  else  { 
11951196            None 
11961197        } 
@@ -1311,24 +1312,29 @@ fn expand_variables(mut value: String, config: &Config) -> String {
13111312    value
13121313} 
13131314
1314- /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line` 
1315- /// variable after the end of the quoted string. 
1316- /// 
1317- /// # Examples 
1318- /// 
1319- /// ``` 
1320- /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\"."; 
1321- /// let first = parse_normalization_string(&mut s); 
1322- /// assert_eq!(first, Some("something (32 bits)".to_owned())); 
1323- /// assert_eq!(s, " -> \"something ($WORD bits)\"."); 
1315+ /// Parses the regex and replacement values of a `//@ normalize-*` header, 
1316+ /// in the format: 
1317+ /// ```text 
1318+ /// normalize-*: "REGEX" -> "REPLACEMENT" 
13241319/// ``` 
1325- fn  parse_normalization_string ( line :  & mut  & str )  -> Option < String >  { 
1326-     // FIXME support escapes in strings. 
1327-     let  begin = line. find ( '"' ) ? + 1 ; 
1328-     let  end = line[ begin..] . find ( '"' ) ? + begin; 
1329-     let  result = line[ begin..end] . to_owned ( ) ; 
1330-     * line = & line[ end + 1 ..] ; 
1331-     Some ( result) 
1320+ fn  parse_normalize_rule ( header :  & str )  -> Option < ( String ,  String ) >  { 
1321+     // FIXME(#126370): A colon after the header name should be mandatory, but 
1322+     // currently is not, and there are many tests that lack the colon. 
1323+     // FIXME: Support escaped double-quotes in strings. 
1324+     let  captures = static_regex ! ( 
1325+         r#"(?x) # (verbose mode regex) 
1326+         ^ 
1327+         [^:\s]+:?\s*            # (header name followed by optional colon) 
1328+         "(?<regex>[^"]*)"       # "REGEX" 
1329+         \s+->\s+                # -> 
1330+         "(?<replacement>[^"]*)" # "REPLACEMENT" 
1331+         $ 
1332+         "# 
1333+     ) 
1334+     . captures ( header) ?; 
1335+     let  regex = captures[ "regex" ] . to_owned ( ) ; 
1336+     let  replacement = captures[ "replacement" ] . to_owned ( ) ; 
1337+     Some ( ( regex,  replacement) ) 
13321338} 
13331339
13341340pub  fn  extract_llvm_version ( version :  & str )  -> Option < u32 >  { 
0 commit comments