use super::GO_BLOCK_RE;
use super::go_blocks::extract_block_parts;
use super::static_regex;
use regex::Regex;
use std::sync::LazyLock;
static NOW_FORMAT_RE: LazyLock<Regex> =
LazyLock::new(|| static_regex(r#"Now\.Format\s+("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')"#));
pub(super) fn preprocess_method_calls(template: &str) -> String {
GO_BLOCK_RE
.replace_all(template, |caps: ®ex::Captures| {
let block = &caps[0];
if !block.contains("Now.Format") {
return block.to_string();
}
let (open, inner, close) = extract_block_parts(block);
let rewritten = NOW_FORMAT_RE
.replace_all(inner, |mcaps: ®ex::Captures| {
let fmt_arg = &mcaps[1];
format!("Now | now_format(format={})", fmt_arg)
})
.to_string();
format!("{}{}{}", open, rewritten, close)
})
.to_string()
}