use dw_parser::pel::InputContext;
const ALLOWED_FUNCTIONS: [(&str, &str); 16] = [
("dw::Core::++", "++"),
("dw::Core::--", "--"),
("dw::Core::contains", "contains"),
("dw::Core::splitBy", "splitBy"),
("dw::Core::trim", "trim"),
("dw::Core::lower", "lower"),
("dw::Core::upper", "upper"),
("dw::Core::sizeOf", "sizeOf"),
("dw::Core::uuid", "uuid"),
("dw::Core::isEmpty", "isEmpty"),
("dw::core::Strings::substringBefore", "substringBefore"),
("dw::core::Strings::substringAfter", "substringAfter"),
(
"dw::core::Strings::substringBeforeLast",
"substringBeforeLast",
),
(
"dw::core::Strings::substringAfterLast",
"substringAfterLast",
),
("dw::core::Binaries::toBase64", "toBase64"),
("dw::core::Binaries::fromBase64", "fromBase64"),
];
const ALLOWED_INPUTS: [&str; 4] = ["payload", "attributes", "vars", "authentication"];
pub fn dw2pel(dw: &str) -> String {
let ctx = InputContext {
inputs: ALLOWED_INPUTS.to_vec(),
functions: ALLOWED_FUNCTIONS.iter().map(|(k, _)| *k).collect(),
};
let result = dw_parser::pel::compile_to_pel_expr("", dw, &ctx);
if result.pel.is_some() {
format!(
"P[{}, \"#[{}]\"]",
result.pel.unwrap(),
dw.replace("\"", "\\\"")
)
} else {
panic!("dw2pel failed: {:?}", result.messages)
}
}