Skip to content

Commit de36c8b

Browse files
authored
[integ] update C++ matcher for spdlog (ttiimm#11)
1 parent 6ef8054 commit de36c8b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl SourceLanguage {
254254
(compound_statement
255255
(expression_statement
256256
(call_expression
257-
function: (identifier) @fname
257+
function: (_) @fname
258258
arguments: (argument_list (string_literal) @arguments)
259259
)
260260
)
@@ -458,7 +458,7 @@ pub fn extract_logging(sources: &[CodeSource], tracker: &ProgressTracker) -> Vec
458458
}
459459
}
460460
}
461-
_ => println!("ignoring {}", result.kind),
461+
_ => eprintln!("ignoring {}", result.kind),
462462
}
463463
// println!("*****");
464464
}

src/source_ref.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static JAVA_PLACEHOLDER_REGEX: LazyLock<Regex> =
9696
LazyLock::new(|| Regex::new(r#"\\?\{.*}"#).unwrap());
9797

9898
static CPP_PLACEHOLDER_REGEX: LazyLock<Regex> =
99-
LazyLock::new(|| Regex::new(r#"%[-+ #0]*\d*(\.\d+)?[hlLzjt]*[diuoxXfFeEgGaAcspn%]"#).unwrap());
99+
LazyLock::new(|| Regex::new(r#"%[-+ #0]*\d*(?:\.\d+)?[hlLzjt]*[diuoxXfFeEgGaAcspn%]|\{(?:([a-zA-Z_][a-zA-Z0-9_.]*)|(\d+))?\s*(?::[^}]*)?}"#).unwrap());
100100

101101
fn placeholder_regex_for(language: SourceLanguage) -> &'static Regex {
102102
match language {
@@ -212,6 +212,17 @@ mod tests {
212212
assert_eq!(args[0], FormatArgument::Placeholder);
213213
}
214214

215+
#[test]
216+
fn test_build_matcher_cpp_spdlog() {
217+
let (matcher, _pat, args) =
218+
build_matcher("they are {0:d} years old", SourceLanguage::Cpp).unwrap();
219+
assert_eq!(
220+
Regex::new(r#"^they are (.+) years old$"#).unwrap().as_str(),
221+
matcher.as_str()
222+
);
223+
assert_eq!(args[0], FormatArgument::Positional(0));
224+
}
225+
215226
#[test]
216227
fn test_build_matcher_none() {
217228
let build_res = build_matcher("%s", SourceLanguage::Cpp);

0 commit comments

Comments
 (0)